Esempio n. 1
0
        /// <summary>
        /// Retrieves a given type of battery statistics.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <param name="startTime">The start time of the data to be aggregated.</param>
        /// <param name="endTime">The end time of the data to be aggregated.</param>
        /// <param name="resultSize">The number of data records to be retrieved.</param>
        /// <returns>Battery statistics data retrieved.</returns>
        /// <privilege>http://tizen.org/privilege/apphistory.read</privilege>
        /// <feature>http://tizen.org/feature/app_history</feature>
        /// <feature>http://tizen.org/feature/battery</feature>
        /// <exception cref="ArgumentException">Thrown when an invalid argument is used.</exception>
        /// <exception cref="InvalidOperationException">Thrown when an invalid operation occurs.</exception>
        /// <exception cref="NotSupportedException">Thrown when the features are not supported.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown when the application has no privilege to retrieve the application history.</exception>
        public IReadOnlyList <BatteryStatisticsData> Query(DateTime startTime, DateTime endTime, uint resultSize)
        {
            CheckTimeSpan(startTime, endTime);
            CheckResultSize(resultSize);

            List <BatteryStatisticsData> result = new List <BatteryStatisticsData>();

            IntPtr cursor = IntPtr.Zero;
            int    error  = Interop.CtxHistory.Query(Uri, (int)ConvertDateTimeToUnixTimestamp(startTime), (int)ConvertDateTimeToUnixTimestamp(endTime), resultSize, out cursor);

            if ((AppHistoryError)error == AppHistoryError.NoData)
            {
                return(result.AsReadOnly());
            }
            else if ((AppHistoryError)error != AppHistoryError.None)
            {
                Log.Error(AppHistoryErrorFactory.LogTag, "Failed to request query battery statistics");
                throw AppHistoryErrorFactory.CheckAndThrowException((AppHistoryError)error, "Failed to request query battery statistics");
            }

            int size;

            error = Interop.CtxHistoryCursor.GetCount(cursor, out size);
            Interop.CtxHistoryCursor.First(cursor);

            for (int i = 0; i < size; i++)
            {
                result.Add(ConvertOutputToStatsData(cursor));
                Interop.CtxHistoryCursor.Next(cursor);
            }
            Interop.CtxHistoryCursor.Destroy(cursor);

            return(result.AsReadOnly());
        }
Esempio n. 2
0
 internal static void CheckResultSize(uint resultSize)
 {
     if (resultSize <= 0)
     {
         Log.Error(AppHistoryErrorFactory.LogTag, "resultSize should be greater than 0");
         throw AppHistoryErrorFactory.CheckAndThrowException(AppHistoryError.InvalidParameter, "resultSize should be greater than 0");
     }
 }
Esempio n. 3
0
 internal static void CheckTimeSpan(DateTime startTime, DateTime endTime)
 {
     if (startTime > endTime)
     {
         Log.Error(AppHistoryErrorFactory.LogTag, "endTime should be greater than startTime");
         throw AppHistoryErrorFactory.CheckAndThrowException(AppHistoryError.InvalidParameter, "endTime should be greater than startTime");
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Gets the last time when the device was fully charged.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <returns>The last time when the device was fully charged.</returns>
        /// <feature>http://tizen.org/feature/app_history</feature>
        /// <feature>http://tizen.org/feature/battery</feature>
        /// <exception cref="NotSupportedException">Thrown when the statistics is not supported.</exception>
        public static DateTime GetLastFullyChargedTime()
        {
            Int64 timestamp;
            int   error = Interop.CtxHistory.GetLastFullyChargedTime(out timestamp);

            if ((AppHistoryError)error != AppHistoryError.None)
            {
                Log.Error(AppHistoryErrorFactory.LogTag, "Failed to request get last fully charged time");
                throw AppHistoryErrorFactory.CheckAndThrowException((AppHistoryError)error, "Failed to request get last fully charged time");
            }

            return(ConvertUnixTimestampToDateTime(timestamp));
        }
Esempio n. 5
0
        /// <summary>
        /// The default constructor of BatteryStatistics class.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <feature>http://tizen.org/feature/app_history</feature>
        /// <feature>http://tizen.org/feature/battery</feature>
        /// <exception cref="InvalidOperationException">Thrown when the method failed due to an internal error.</exception>
        /// <exception cref="NotSupportedException">Thrown when the features are not supported.</exception>
        public BatteryStatistics()
        {
            SortOrder = SortOrderType.ConsumptionMost;
            Uri       = ConvertSortOrderToString((int)SortOrder);

            bool isSupported = false;
            int  error       = Interop.CtxHistory.IsSupported(Uri, out isSupported);

            if ((AppHistoryError)error != AppHistoryError.None)
            {
                throw AppHistoryErrorFactory.CheckAndThrowException((AppHistoryError)error, Uri);
            }

            if (!isSupported)
            {
                throw AppHistoryErrorFactory.CheckAndThrowException(AppHistoryError.NotSupported, Uri);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// The default constructor of UsageStatistics class.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <feature>http://tizen.org/feature/app_history</feature>
        /// <exception cref="InvalidOperationException">Thrown when the method failed due to an internal error.</exception>
        /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
        public UsageStatistics()
        {
            SortOrder = SortOrderType.LastLaunchTimeNewest;
            Uri       = ConvertSortOrderToString((int)SortOrder);

            bool isSupported = false;
            int  error       = Interop.CtxHistory.IsSupported(Uri, out isSupported);

            if ((AppHistoryError)error != AppHistoryError.None)
            {
                throw AppHistoryErrorFactory.CheckAndThrowException((AppHistoryError)error, Uri);
            }

            if (!isSupported)
            {
                throw AppHistoryErrorFactory.CheckAndThrowException(AppHistoryError.OperationFailed, Uri);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// The constructor of BatteryStatistics class.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <param name="order">The criteria of the battery statistics sorted by.</param>
        /// <feature>http://tizen.org/feature/app_history</feature>
        /// <feature>http://tizen.org/feature/battery</feature>
        /// <exception cref="ArgumentException">Thrown when an invalid argument is used.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the method failed due to an internal error.</exception>
        /// <exception cref="NotSupportedException">Thrown when the features are not supported.</exception>
        public BatteryStatistics(SortOrderType order)
        {
            SortOrder = order;
            Uri       = ConvertSortOrderToString((int)SortOrder);

            if (Uri == null)
            {
                throw AppHistoryErrorFactory.CheckAndThrowException(AppHistoryError.InvalidParameter, "Invalid SortOrderType");
            }

            bool isSupported = false;
            int  error       = Interop.CtxHistory.IsSupported(Uri, out isSupported);

            if ((AppHistoryError)error != AppHistoryError.None)
            {
                throw AppHistoryErrorFactory.CheckAndThrowException((AppHistoryError)error, Uri);
            }

            if (!isSupported)
            {
                throw AppHistoryErrorFactory.CheckAndThrowException(AppHistoryError.NotSupported, Uri);
            }
        }