Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2543b88a authored by Meng Wang's avatar Meng Wang
Browse files

Replace IDeviceIdleController with PowerWhitelistManager

Bug: 137202333
Test: make
Change-Id: I22303f4c38be887f4468f204757d7246df35cd83
parent c03e5ee5
Loading
Loading
Loading
Loading
+16 −22
Original line number Diff line number Diff line
@@ -47,9 +47,9 @@ import android.os.AsyncResult;
import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
import android.os.IDeviceIdleController;
import android.os.Message;
import android.os.PowerManager;
import android.os.PowerWhitelistManager;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
@@ -238,8 +238,7 @@ public abstract class InboundSmsHandler extends StateMachine {

    private LocalLog mLocalLog = new LocalLog(64);

    @UnsupportedAppUsage
    IDeviceIdleController mDeviceIdleController;
    PowerWhitelistManager mPowerWhitelistManager;

    protected static boolean sEnableCbModule = false;

@@ -286,8 +285,8 @@ public abstract class InboundSmsHandler extends StateMachine {
        mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, name);
        mWakeLock.acquire();    // wake lock released after we enter idle state
        mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
        mDeviceIdleController = TelephonyComponentFactory.getInstance()
                .inject(IDeviceIdleController.class.getName()).getIDeviceIdleController();
        mPowerWhitelistManager =
                (PowerWhitelistManager) mContext.getSystemService(Context.POWER_WHITELIST_MANAGER);
        mCellBroadcastServiceManager = new CellBroadcastServiceManager(context, phone);

        addState(mDefaultState);
@@ -1237,14 +1236,11 @@ public abstract class InboundSmsHandler extends StateMachine {
            bopts.setBackgroundActivityStartsAllowed(true);
            bundle = bopts.toBundle();
        }
        try {
            long duration = mDeviceIdleController.addPowerSaveTempWhitelistAppForSms(
                    pkgName, 0, reason);
        long duration = mPowerWhitelistManager.whitelistAppTemporarilyForEvent(
                pkgName, PowerWhitelistManager.EVENT_SMS, reason);
        if (bopts == null) bopts = BroadcastOptions.makeBasic();
        bopts.setTemporaryAppWhitelistDuration(duration);
        bundle = bopts.toBundle();
        } catch (RemoteException e) {
        }

        return bundle;
    }
@@ -1496,15 +1492,13 @@ public abstract class InboundSmsHandler extends StateMachine {
                intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
                // Only the primary user will receive notification of incoming mms.
                // That app will do the actual downloading of the mms.
                Bundle options = null;
                try {
                    long duration = mDeviceIdleController.addPowerSaveTempWhitelistAppForMms(
                            mContext.getPackageName(), 0, "mms-broadcast");
                long duration = mPowerWhitelistManager.whitelistAppTemporarilyForEvent(
                        mContext.getPackageName(),
                        PowerWhitelistManager.EVENT_MMS,
                        "mms-broadcast");
                BroadcastOptions bopts = BroadcastOptions.makeBasic();
                bopts.setTemporaryAppWhitelistDuration(duration);
                    options = bopts.toBundle();
                } catch (RemoteException e) {
                }
                Bundle options = bopts.toBundle();

                String mimeType = intent.getType();
                dispatchIntent(intent, WapPushOverSms.getPermissionForType(mimeType),
+0 −7
Original line number Diff line number Diff line
@@ -22,9 +22,7 @@ import android.content.Context;
import android.content.res.XmlResourceParser;
import android.database.Cursor;
import android.os.Handler;
import android.os.IDeviceIdleController;
import android.os.Looper;
import android.os.ServiceManager;
import android.system.ErrnoException;
import android.system.Os;
import android.system.OsConstants;
@@ -409,11 +407,6 @@ public class TelephonyComponentFactory {
        return CdmaSubscriptionSourceManager.getInstance(context, ci, h, what, obj);
    }

    public IDeviceIdleController getIDeviceIdleController() {
        return IDeviceIdleController.Stub.asInterface(
                ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
    }

    public LocaleTracker makeLocaleTracker(Phone phone, NitzStateMachine nitzStateMachine,
                                           Looper looper) {
        return new LocaleTracker(phone, nitzStateMachine, looper);
+11 −15
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ import android.database.sqlite.SQLiteException;
import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import android.os.IDeviceIdleController;
import android.os.PowerWhitelistManager;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
@@ -73,8 +73,7 @@ public class WapPushOverSms implements ServiceConnection {

    @UnsupportedAppUsage
    private final Context mContext;
    @UnsupportedAppUsage
    private IDeviceIdleController mDeviceIdleController;
    PowerWhitelistManager mPowerWhitelistManager;

    private String mWapPushManagerPackage;

@@ -136,8 +135,8 @@ public class WapPushOverSms implements ServiceConnection {

    public WapPushOverSms(Context context) {
        mContext = context;
        mDeviceIdleController = TelephonyComponentFactory.getInstance()
                .inject(IDeviceIdleController.class.getName()).getIDeviceIdleController();
        mPowerWhitelistManager =
                (PowerWhitelistManager) mContext.getSystemService(Context.POWER_WHITELIST_MANAGER);

        UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);

@@ -351,8 +350,8 @@ public class WapPushOverSms implements ServiceConnection {
                    if (DBG) Rlog.w(TAG, "wap push manager not found!");
                } else {
                    synchronized (this) {
                        mDeviceIdleController.addPowerSaveTempWhitelistAppForMms(
                                mWapPushManagerPackage, 0, "mms-mgr");
                        mPowerWhitelistManager.whitelistAppTemporarilyForEvent(
                                mWapPushManagerPackage, PowerWhitelistManager.EVENT_MMS, "mms-mgr");
                    }

                    Intent intent = new Intent();
@@ -409,14 +408,11 @@ public class WapPushOverSms implements ServiceConnection {
            intent.setComponent(componentName);
            if (DBG) Rlog.v(TAG, "Delivering MMS to: " + componentName.getPackageName() +
                    " " + componentName.getClassName());
            try {
                long duration = mDeviceIdleController.addPowerSaveTempWhitelistAppForMms(
                        componentName.getPackageName(), 0, "mms-app");
            long duration = mPowerWhitelistManager.whitelistAppTemporarilyForEvent(
                    componentName.getPackageName(), PowerWhitelistManager.EVENT_MMS, "mms-app");
            BroadcastOptions bopts = BroadcastOptions.makeBasic();
            bopts.setTemporaryAppWhitelistDuration(duration);
            options = bopts.toBundle();
            } catch (RemoteException e) {
            }
        }

        handler.dispatchIntent(intent, getPermissionForType(result.mimeType),
+4 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.IInterface;
import android.os.PersistableBundle;
import android.os.PowerWhitelistManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.preference.PreferenceManager;
@@ -258,6 +259,8 @@ public class ContextFixture implements TestFixture<Context> {
                    // PowerManager and DisplayManager are final classes so cannot be mocked,
                    // return real services.
                    return TestApplication.getAppContext().getSystemService(name);
                case Context.POWER_WHITELIST_MANAGER:
                    return mPowerWhitelistManager;
                default:
                    return null;
            }
@@ -585,6 +588,7 @@ public class ContextFixture implements TestFixture<Context> {
    private final TelephonyRegistryManager mTelephonyRegistryManager =
        mock(TelephonyRegistryManager.class);
    private final BatteryStatsManager mBatteryStatsManager = mock(BatteryStatsManager.class);
    private final PowerWhitelistManager mPowerWhitelistManager = mock(PowerWhitelistManager.class);

    private final ContentProvider mContentProvider = spy(new FakeContentProvider());

+0 −5
Original line number Diff line number Diff line
@@ -43,7 +43,6 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.IDeviceIdleController;
import android.os.Looper;
import android.os.Message;
import android.os.MessageQueue;
@@ -189,8 +188,6 @@ public abstract class TelephonyTest {
    @Mock
    protected SimulatedCommandsVerifier mSimulatedCommandsVerifier;
    @Mock
    protected IDeviceIdleController mIDeviceIdleController;
    @Mock
    protected InboundSmsHandler mInboundSmsHandler;
    @Mock
    protected WspTypeDecoder mWspTypeDecoder;
@@ -436,8 +433,6 @@ public abstract class TelephonyTest {
                .getCdmaSubscriptionSourceManagerInstance(nullable(Context.class),
                        nullable(CommandsInterface.class), nullable(Handler.class),
                        anyInt(), nullable(Object.class));
        doReturn(mIDeviceIdleController).when(mTelephonyComponentFactory)
                .getIDeviceIdleController();
        doReturn(mImsExternalCallTracker).when(mTelephonyComponentFactory)
                .makeImsExternalCallTracker(nullable(ImsPhone.class));
        doReturn(mAppSmsManager).when(mTelephonyComponentFactory)