Loading src/com/android/server/telecom/DeviceIdleControllerAdapter.java 0 → 100644 +57 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.telecom; import android.annotation.NonNull; import android.content.Context; import android.os.PowerWhitelistManager; import android.os.RemoteException; import android.telecom.Log; import com.android.internal.telecom.IDeviceIdleControllerAdapter; /** * Telecom is in the same process as the {@link PowerWhitelistManager}, so we can not make direct * calls to the manager interface, since they will fail in the DeviceIdleController * (see {@link Context#enforceCallingPermission(String, String)}). Instead, we must access it * through SystemService#getLocalService, which is only accessible to the Telecom * core loader service (TelecomLoaderService). Unfortunately, due to the architecture, this means * we must use a Binder to allow services such as this to be accessible. */ public class DeviceIdleControllerAdapter { private static final String TAG = "DeviceIdleControllerAdapter"; private final IDeviceIdleControllerAdapter mAdapter; public DeviceIdleControllerAdapter(IDeviceIdleControllerAdapter adapter) { mAdapter = adapter; } /** * Exempts an application from power restrictions for the duration specified. See * DeviceIdleController for more information on how this works. */ public void exemptAppTemporarilyForEvent(@NonNull String packageName, long duration, int userHandle, @NonNull String reason) { try { mAdapter.exemptAppTemporarilyForEvent(packageName, duration, userHandle, reason); } catch (RemoteException e) { Log.w(TAG, "exemptAppTemporarilyForEvent e=" + e.getMessage()); } } } src/com/android/server/telecom/InternalServiceRetrieverAdapter.java 0 → 100644 +44 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.telecom; import android.os.RemoteException; import com.android.internal.telecom.IInternalServiceRetriever; /** * Contains all services that Telecom must access that are only accessible as a local service as * part of the SYSTEM process. */ public class InternalServiceRetrieverAdapter { private final IInternalServiceRetriever mRetriever; public InternalServiceRetrieverAdapter(IInternalServiceRetriever retriever) { mRetriever = retriever; } public DeviceIdleControllerAdapter getDeviceIdleController() { try { return new DeviceIdleControllerAdapter(mRetriever.getDeviceIdleController()); } catch (RemoteException e) { // This should not happen - if it does, there is a bad configuration as this should // all be local. throw new IllegalStateException(e); } } } src/com/android/server/telecom/TelecomSystem.java +4 −2 Original line number Diff line number Diff line Loading @@ -207,7 +207,8 @@ public class TelecomSystem { ClockProxy clockProxy, RoleManagerAdapter roleManagerAdapter, IncomingCallFilter.Factory incomingCallFilterFactory, ContactsAsyncHelper.Factory contactsAsyncHelperFactory) { ContactsAsyncHelper.Factory contactsAsyncHelperFactory, DeviceIdleControllerAdapter deviceIdleControllerAdapter) { mContext = context.getApplicationContext(); LogUtils.initLogging(mContext); DefaultDialerManagerAdapter defaultDialerAdapter = Loading Loading @@ -241,7 +242,8 @@ public class TelecomSystem { SystemStateHelper systemStateHelper = new SystemStateHelper(mContext); mMissedCallNotifier = missedCallNotifierImplFactory .makeMissedCallNotifierImpl(mContext, mPhoneAccountRegistrar, defaultDialerCache); .makeMissedCallNotifierImpl(mContext, mPhoneAccountRegistrar, defaultDialerCache, deviceIdleControllerAdapter); DisconnectedCallNotifier.Factory disconnectedCallNotifierFactory = new DisconnectedCallNotifier.Default(); Loading src/com/android/server/telecom/Timeouts.java +11 −0 Original line number Diff line number Diff line Loading @@ -211,4 +211,15 @@ public final class Timeouts { public static long getCallRecordingToneRepeatIntervalMillis(ContentResolver contentResolver) { return get(contentResolver, "call_recording_tone_repeat_interval", 15000L /* 15 seconds */); } /** * Returns the number of milliseconds for which the system should exempt the default dialer from * power save restrictions due to the dialer needing to handle a missed call notification * (update call log, check VVM, etc...). */ public static long getDialerMissedCallPowerSaveExemptionTimeMillis( ContentResolver contentResolver) { return get(contentResolver, "dialer_missed_call_power_save_exemption_time_millis", 30000L /*30 seconds*/); } } src/com/android/server/telecom/components/TelecomService.java +25 −9 Original line number Diff line number Diff line Loading @@ -30,6 +30,10 @@ import android.os.SystemClock; import android.telecom.Log; import android.telecom.CallerInfoAsyncQuery; import com.android.internal.telecom.IInternalServiceRetriever; import com.android.internal.telecom.ITelecomLoader; import com.android.internal.telecom.ITelecomService; import com.android.server.telecom.AsyncRingtonePlayer; import com.android.server.telecom.BluetoothAdapterProxy; import com.android.server.telecom.BluetoothPhoneServiceImpl; Loading @@ -41,16 +45,17 @@ import com.android.server.telecom.ClockProxy; import com.android.server.telecom.ConnectionServiceFocusManager; import com.android.server.telecom.ContactsAsyncHelper; import com.android.server.telecom.DefaultDialerCache; import com.android.server.telecom.DeviceIdleControllerAdapter; import com.android.server.telecom.HeadsetMediaButton; import com.android.server.telecom.HeadsetMediaButtonFactory; import com.android.server.telecom.InCallWakeLockControllerFactory; import com.android.server.telecom.CallAudioManager; import com.android.server.telecom.InternalServiceRetrieverAdapter; import com.android.server.telecom.PhoneAccountRegistrar; import com.android.server.telecom.PhoneNumberUtilsAdapterImpl; import com.android.server.telecom.ProximitySensorManagerFactory; import com.android.server.telecom.InCallWakeLockController; import com.android.server.telecom.ProximitySensorManager; import com.android.server.telecom.R; import com.android.server.telecom.RoleManagerAdapterImpl; import com.android.server.telecom.TelecomSystem; import com.android.server.telecom.TelecomWakeLock; Loading @@ -68,11 +73,18 @@ public class TelecomService extends Service implements TelecomSystem.Component { @Override public IBinder onBind(Intent intent) { Log.d(this, "onBind"); initializeTelecomSystem(this); return new ITelecomLoader.Stub() { @Override public ITelecomService createTelecomService(IInternalServiceRetriever retriever) { InternalServiceRetrieverAdapter adapter = new InternalServiceRetrieverAdapter(retriever); initializeTelecomSystem(TelecomService.this, adapter); synchronized (getTelecomSystem().getLock()) { return getTelecomSystem().getTelecomServiceImpl().getBinder(); } } }; } /** * This method is to be called by components (Activitys, Services, ...) to initialize the Loading @@ -84,7 +96,8 @@ public class TelecomService extends Service implements TelecomSystem.Component { * * @param context */ static void initializeTelecomSystem(Context context) { static void initializeTelecomSystem(Context context, InternalServiceRetrieverAdapter internalServiceRetriever) { if (TelecomSystem.getInstance() == null) { NotificationChannelManager notificationChannelManager = new NotificationChannelManager(); Loading @@ -98,9 +111,11 @@ public class TelecomService extends Service implements TelecomSystem.Component { public MissedCallNotifierImpl makeMissedCallNotifierImpl( Context context, PhoneAccountRegistrar phoneAccountRegistrar, DefaultDialerCache defaultDialerCache) { DefaultDialerCache defaultDialerCache, DeviceIdleControllerAdapter idleControllerAdapter) { return new MissedCallNotifierImpl(context, phoneAccountRegistrar, defaultDialerCache); phoneAccountRegistrar, defaultDialerCache, idleControllerAdapter); } }, new CallerInfoAsyncQueryFactory() { Loading Loading @@ -191,7 +206,8 @@ public class TelecomService extends Service implements TelecomSystem.Component { new RoleManagerAdapterImpl(context, (RoleManager) context.getSystemService(Context.ROLE_SERVICE)), new IncomingCallFilter.Factory(), new ContactsAsyncHelper.Factory())); new ContactsAsyncHelper.Factory(), internalServiceRetriever.getDeviceIdleController())); } if (BluetoothAdapter.getDefaultAdapter() != null) { context.startService(new Intent(context, BluetoothPhoneService.class)); Loading Loading
src/com/android/server/telecom/DeviceIdleControllerAdapter.java 0 → 100644 +57 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.telecom; import android.annotation.NonNull; import android.content.Context; import android.os.PowerWhitelistManager; import android.os.RemoteException; import android.telecom.Log; import com.android.internal.telecom.IDeviceIdleControllerAdapter; /** * Telecom is in the same process as the {@link PowerWhitelistManager}, so we can not make direct * calls to the manager interface, since they will fail in the DeviceIdleController * (see {@link Context#enforceCallingPermission(String, String)}). Instead, we must access it * through SystemService#getLocalService, which is only accessible to the Telecom * core loader service (TelecomLoaderService). Unfortunately, due to the architecture, this means * we must use a Binder to allow services such as this to be accessible. */ public class DeviceIdleControllerAdapter { private static final String TAG = "DeviceIdleControllerAdapter"; private final IDeviceIdleControllerAdapter mAdapter; public DeviceIdleControllerAdapter(IDeviceIdleControllerAdapter adapter) { mAdapter = adapter; } /** * Exempts an application from power restrictions for the duration specified. See * DeviceIdleController for more information on how this works. */ public void exemptAppTemporarilyForEvent(@NonNull String packageName, long duration, int userHandle, @NonNull String reason) { try { mAdapter.exemptAppTemporarilyForEvent(packageName, duration, userHandle, reason); } catch (RemoteException e) { Log.w(TAG, "exemptAppTemporarilyForEvent e=" + e.getMessage()); } } }
src/com/android/server/telecom/InternalServiceRetrieverAdapter.java 0 → 100644 +44 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.telecom; import android.os.RemoteException; import com.android.internal.telecom.IInternalServiceRetriever; /** * Contains all services that Telecom must access that are only accessible as a local service as * part of the SYSTEM process. */ public class InternalServiceRetrieverAdapter { private final IInternalServiceRetriever mRetriever; public InternalServiceRetrieverAdapter(IInternalServiceRetriever retriever) { mRetriever = retriever; } public DeviceIdleControllerAdapter getDeviceIdleController() { try { return new DeviceIdleControllerAdapter(mRetriever.getDeviceIdleController()); } catch (RemoteException e) { // This should not happen - if it does, there is a bad configuration as this should // all be local. throw new IllegalStateException(e); } } }
src/com/android/server/telecom/TelecomSystem.java +4 −2 Original line number Diff line number Diff line Loading @@ -207,7 +207,8 @@ public class TelecomSystem { ClockProxy clockProxy, RoleManagerAdapter roleManagerAdapter, IncomingCallFilter.Factory incomingCallFilterFactory, ContactsAsyncHelper.Factory contactsAsyncHelperFactory) { ContactsAsyncHelper.Factory contactsAsyncHelperFactory, DeviceIdleControllerAdapter deviceIdleControllerAdapter) { mContext = context.getApplicationContext(); LogUtils.initLogging(mContext); DefaultDialerManagerAdapter defaultDialerAdapter = Loading Loading @@ -241,7 +242,8 @@ public class TelecomSystem { SystemStateHelper systemStateHelper = new SystemStateHelper(mContext); mMissedCallNotifier = missedCallNotifierImplFactory .makeMissedCallNotifierImpl(mContext, mPhoneAccountRegistrar, defaultDialerCache); .makeMissedCallNotifierImpl(mContext, mPhoneAccountRegistrar, defaultDialerCache, deviceIdleControllerAdapter); DisconnectedCallNotifier.Factory disconnectedCallNotifierFactory = new DisconnectedCallNotifier.Default(); Loading
src/com/android/server/telecom/Timeouts.java +11 −0 Original line number Diff line number Diff line Loading @@ -211,4 +211,15 @@ public final class Timeouts { public static long getCallRecordingToneRepeatIntervalMillis(ContentResolver contentResolver) { return get(contentResolver, "call_recording_tone_repeat_interval", 15000L /* 15 seconds */); } /** * Returns the number of milliseconds for which the system should exempt the default dialer from * power save restrictions due to the dialer needing to handle a missed call notification * (update call log, check VVM, etc...). */ public static long getDialerMissedCallPowerSaveExemptionTimeMillis( ContentResolver contentResolver) { return get(contentResolver, "dialer_missed_call_power_save_exemption_time_millis", 30000L /*30 seconds*/); } }
src/com/android/server/telecom/components/TelecomService.java +25 −9 Original line number Diff line number Diff line Loading @@ -30,6 +30,10 @@ import android.os.SystemClock; import android.telecom.Log; import android.telecom.CallerInfoAsyncQuery; import com.android.internal.telecom.IInternalServiceRetriever; import com.android.internal.telecom.ITelecomLoader; import com.android.internal.telecom.ITelecomService; import com.android.server.telecom.AsyncRingtonePlayer; import com.android.server.telecom.BluetoothAdapterProxy; import com.android.server.telecom.BluetoothPhoneServiceImpl; Loading @@ -41,16 +45,17 @@ import com.android.server.telecom.ClockProxy; import com.android.server.telecom.ConnectionServiceFocusManager; import com.android.server.telecom.ContactsAsyncHelper; import com.android.server.telecom.DefaultDialerCache; import com.android.server.telecom.DeviceIdleControllerAdapter; import com.android.server.telecom.HeadsetMediaButton; import com.android.server.telecom.HeadsetMediaButtonFactory; import com.android.server.telecom.InCallWakeLockControllerFactory; import com.android.server.telecom.CallAudioManager; import com.android.server.telecom.InternalServiceRetrieverAdapter; import com.android.server.telecom.PhoneAccountRegistrar; import com.android.server.telecom.PhoneNumberUtilsAdapterImpl; import com.android.server.telecom.ProximitySensorManagerFactory; import com.android.server.telecom.InCallWakeLockController; import com.android.server.telecom.ProximitySensorManager; import com.android.server.telecom.R; import com.android.server.telecom.RoleManagerAdapterImpl; import com.android.server.telecom.TelecomSystem; import com.android.server.telecom.TelecomWakeLock; Loading @@ -68,11 +73,18 @@ public class TelecomService extends Service implements TelecomSystem.Component { @Override public IBinder onBind(Intent intent) { Log.d(this, "onBind"); initializeTelecomSystem(this); return new ITelecomLoader.Stub() { @Override public ITelecomService createTelecomService(IInternalServiceRetriever retriever) { InternalServiceRetrieverAdapter adapter = new InternalServiceRetrieverAdapter(retriever); initializeTelecomSystem(TelecomService.this, adapter); synchronized (getTelecomSystem().getLock()) { return getTelecomSystem().getTelecomServiceImpl().getBinder(); } } }; } /** * This method is to be called by components (Activitys, Services, ...) to initialize the Loading @@ -84,7 +96,8 @@ public class TelecomService extends Service implements TelecomSystem.Component { * * @param context */ static void initializeTelecomSystem(Context context) { static void initializeTelecomSystem(Context context, InternalServiceRetrieverAdapter internalServiceRetriever) { if (TelecomSystem.getInstance() == null) { NotificationChannelManager notificationChannelManager = new NotificationChannelManager(); Loading @@ -98,9 +111,11 @@ public class TelecomService extends Service implements TelecomSystem.Component { public MissedCallNotifierImpl makeMissedCallNotifierImpl( Context context, PhoneAccountRegistrar phoneAccountRegistrar, DefaultDialerCache defaultDialerCache) { DefaultDialerCache defaultDialerCache, DeviceIdleControllerAdapter idleControllerAdapter) { return new MissedCallNotifierImpl(context, phoneAccountRegistrar, defaultDialerCache); phoneAccountRegistrar, defaultDialerCache, idleControllerAdapter); } }, new CallerInfoAsyncQueryFactory() { Loading Loading @@ -191,7 +206,8 @@ public class TelecomService extends Service implements TelecomSystem.Component { new RoleManagerAdapterImpl(context, (RoleManager) context.getSystemService(Context.ROLE_SERVICE)), new IncomingCallFilter.Factory(), new ContactsAsyncHelper.Factory())); new ContactsAsyncHelper.Factory(), internalServiceRetriever.getDeviceIdleController())); } if (BluetoothAdapter.getDefaultAdapter() != null) { context.startService(new Intent(context, BluetoothPhoneService.class)); Loading