1 /* 2 * Copyright (C) 2023 The Android Open Source Project 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 package com.android.devicelockcontroller.storage; 18 19 import android.app.Service; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.os.IBinder; 23 24 import com.android.devicelockcontroller.common.DeviceLockConstants.DeviceProvisionState; 25 import com.android.devicelockcontroller.policy.DeviceStateController.DeviceState; 26 import com.android.devicelockcontroller.policy.FinalizationControllerImpl.FinalizationState; 27 import com.android.devicelockcontroller.util.LogUtil; 28 29 /** 30 * A class exposing Global Parameters as a service. 31 */ 32 public final class GlobalParametersService extends Service { 33 private static final String TAG = "GlobalParametersService"; 34 35 private Context mContext; 36 37 private final IGlobalParametersService.Stub mBinder = 38 new IGlobalParametersService.Stub() { 39 @Override 40 public void clear() { 41 GlobalParameters.clear(mContext); 42 } 43 44 @Override 45 public void dump() { 46 GlobalParameters.dump(mContext); 47 } 48 49 @Override 50 public boolean isProvisionReady() { 51 return GlobalParameters.isProvisionReady(mContext); 52 } 53 54 @Override 55 public void setProvisionReady(boolean isProvisionReady) { 56 GlobalParameters.setProvisionReady(mContext, isProvisionReady); 57 } 58 59 @Override 60 public String getRegisteredDeviceId() { 61 return GlobalParameters.getRegisteredDeviceId(mContext); 62 } 63 64 @Override 65 public void setRegisteredDeviceId(String registeredDeviceId) { 66 GlobalParameters.setRegisteredDeviceId(mContext, registeredDeviceId); 67 } 68 69 @Override 70 public boolean isProvisionForced() { 71 return GlobalParameters.isProvisionForced(mContext); 72 } 73 74 @Override 75 public void setProvisionForced(boolean isForced) { 76 GlobalParameters.setProvisionForced(mContext, isForced); 77 } 78 79 @Override 80 public int getDeviceState() { 81 return GlobalParameters.getDeviceState(mContext); 82 } 83 84 @Override 85 public void setDeviceState(@DeviceState int state) { 86 GlobalParameters.setDeviceState(mContext, state); 87 } 88 89 @Override 90 public @FinalizationState int getFinalizationState() { 91 return GlobalParameters.getFinalizationState(mContext); 92 } 93 94 @Override 95 public void setFinalizationState(@FinalizationState int state) { 96 GlobalParameters.setFinalizationState(mContext, state); 97 } 98 99 @Override 100 @DeviceProvisionState 101 public int getLastReceivedProvisionState() { 102 return GlobalParameters.getLastReceivedProvisionState(mContext); 103 } 104 105 @Override 106 public void setLastReceivedProvisionState( 107 @DeviceProvisionState int provisionState) { 108 GlobalParameters.setLastReceivedProvisionState(mContext, provisionState); 109 } 110 }; 111 112 @Override onCreate()113 public void onCreate() { 114 LogUtil.d(TAG, "onCreate"); 115 mContext = this; 116 } 117 118 @Override onBind(Intent intent)119 public IBinder onBind(Intent intent) { 120 return mBinder; 121 } 122 } 123