Fix exception handling for Satellite
[platform/core/csapi/tizenfx.git] / src / Tizen.Location / Tizen.Location / LocationError.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using Tizen.Internals.Errors;
19
20 namespace Tizen.Location
21 {
22     internal static class LocationManagerError
23     {
24         public const int Base = -0x02C00000;
25         public const int BoundsBase = -0x02C00000 | 0x20;
26     }
27
28     /// <summary>
29     /// Location Manager error codes
30     /// </summary>
31     public enum LocationError
32     {
33         None = ErrorCode.None,/**< Successful */
34         OutOfMemoryError = ErrorCode.OutOfMemory,/**< Out of memory error */
35         InvalidParameter = ErrorCode.InvalidParameter,/**< Invalid parameter */
36         AcessibilityNotallowed = ErrorCode.PermissionDenied,/**< Permission denied */
37         NotSupported = ErrorCode.NotSupported,/**< Address family not supported */
38         IncorrectMethod = LocationManagerError.Base | 0x01,/**< Location manager contains incorrect method for a given call */
39         NetworkFailed = LocationManagerError.Base | 0x02,/**< Network unavailable */
40         ServiceNotAvailable = LocationManagerError.Base | 0x03,/**< Location service is not available */
41         GPSSettingOff = LocationManagerError.Base | 0x04,/**< GPS/WPS, or MOCK setting is not enabled */
42         SecuirtyRestricted = LocationManagerError.Base | 0x05,/**< Restricted by security system policy */
43         SettingOff = GPSSettingOff/**< GPS/WPS, or MOCK setting is not enabled */
44     }
45
46     /// <summary>
47     /// Location Boundary error codes
48     /// </summary>
49     public enum LocationBoundError
50     {
51         None = ErrorCode.None,/**< Successful */
52         OutOfMemoryError = ErrorCode.OutOfMemory,/**< Out of memory error */
53         InvalidParameter = ErrorCode.InvalidParameter,/**< Invalid parameter */
54         NotSupported = ErrorCode.NotSupported,/**< Not supported */
55         IncorrectType = LocationManagerError.BoundsBase | 0x01,/**< Incorrect bounds type for a given call */
56         IsAdded = LocationManagerError.BoundsBase | 0x02/**< Cannot remove bounds handle from location manager   */
57     }
58
59     internal static class LocationErrorFactory
60     {
61         internal static Exception ThrowLocationException(int errCode)
62         {
63             Log.Error(Globals.LogTag, "Throw Location Exception : " + errCode);
64             LocationError error = (LocationError)errCode;
65             switch (error)
66             {
67                 case LocationError.OutOfMemoryError:
68                     return new InvalidOperationException("Out of memory error");
69                 case LocationError.InvalidParameter:
70                     return new ArgumentException("Invalid Parameter passed");
71                 case LocationError.AcessibilityNotallowed:
72                     return new UnauthorizedAccessException("Accesibility not allowed");
73                 case LocationError.NotSupported:
74                     return new NotSupportedException("Not supported");
75                 case LocationError.IncorrectMethod:
76                     return new InvalidOperationException("Incorrect method used");
77                 case LocationError.NetworkFailed:
78                     return new InvalidOperationException("Network failed");
79                 case LocationError.ServiceNotAvailable:
80                     return new InvalidOperationException("Service not available");
81                 case LocationError.SettingOff:
82                     return new InvalidOperationException("Current locationtype setting is off");
83                 case LocationError.SecuirtyRestricted:
84                     return new InvalidOperationException("Security Restricted");
85                 default:
86                     return new InvalidOperationException("Unknown Error");
87             }
88         }
89
90         internal static Exception ThrowLocationBoundaryException(int errCode)
91         {
92             LocationBoundError error = (LocationBoundError)errCode;
93             switch (error)
94             {
95                 case LocationBoundError.OutOfMemoryError:
96                     return new InvalidOperationException("Out of memory exception");
97                 case LocationBoundError.InvalidParameter:
98                     return new ArgumentException("Invalid parameter passed");
99                 case LocationBoundError.NotSupported:
100                     return new NotSupportedException("Not supported");
101                 case LocationBoundError.IncorrectType:
102                     return new InvalidOperationException("Incorrect type passed");
103                 case LocationBoundError.IsAdded:
104                     return new InvalidOperationException("Boundary is not addded");
105                 default:
106                     return new InvalidOperationException("Unknown Error");
107             }
108         }
109     }
110 }