1 /* 2 * Copyright (C) 2020 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.server.telecom; 18 19 import android.annotation.NonNull; 20 import android.content.Context; 21 import android.os.PowerWhitelistManager; 22 import android.os.RemoteException; 23 import android.telecom.Log; 24 25 import com.android.internal.telecom.IDeviceIdleControllerAdapter; 26 27 /** 28 * Telecom is in the same process as the {@link PowerWhitelistManager}, so we can not make direct 29 * calls to the manager interface, since they will fail in the DeviceIdleController 30 * (see {@link Context#enforceCallingPermission(String, String)}). Instead, we must access it 31 * through SystemService#getLocalService, which is only accessible to the Telecom 32 * core loader service (TelecomLoaderService). Unfortunately, due to the architecture, this means 33 * we must use a Binder to allow services such as this to be accessible. 34 */ 35 public class DeviceIdleControllerAdapter { 36 37 private static final String TAG = "DeviceIdleControllerAdapter"; 38 39 private final IDeviceIdleControllerAdapter mAdapter; 40 DeviceIdleControllerAdapter(IDeviceIdleControllerAdapter adapter)41 public DeviceIdleControllerAdapter(IDeviceIdleControllerAdapter adapter) { 42 mAdapter = adapter; 43 } 44 45 /** 46 * Exempts an application from power restrictions for the duration specified. See 47 * DeviceIdleController for more information on how this works. 48 */ exemptAppTemporarilyForEvent(@onNull String packageName, long duration, int userHandle, @NonNull String reason)49 public void exemptAppTemporarilyForEvent(@NonNull String packageName, long duration, 50 int userHandle, @NonNull String reason) { 51 try { 52 mAdapter.exemptAppTemporarilyForEvent(packageName, duration, userHandle, reason); 53 } catch (RemoteException e) { 54 Log.w(TAG, "exemptAppTemporarilyForEvent e=" + e.getMessage()); 55 } 56 } 57 } 58