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

Commit 57f215d9 authored by paulhu's avatar paulhu
Browse files

Replace PendingIntent/NotificationManager @hide APIs

Tethering used some PendingIntent/NotificationManager @hide APIs
but they are not able to call now. Replace them with similar
System APIs.

Bug: 122085773
Test: atest TetheringTests
Change-Id: I2201d0e44a6356b8b1974ce0ed80d9913a7aeff5
parent e5b7ec01
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
@@ -688,7 +688,8 @@ public class Tethering {
    @VisibleForTesting
    protected void showTetheredNotification(int id, boolean tetheringOn) {
        NotificationManager notificationManager =
                (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
                (NotificationManager) mContext.createContextAsUser(UserHandle.ALL, 0)
                        .getSystemService(Context.NOTIFICATION_SERVICE);
        if (notificationManager == null) {
            return;
        }
@@ -716,8 +717,7 @@ public class Tethering {
            if (mLastNotificationId == icon) {
                return;
            }
            notificationManager.cancelAsUser(null, mLastNotificationId,
                    UserHandle.ALL);
            notificationManager.cancel(null, mLastNotificationId);
            mLastNotificationId = 0;
        }

@@ -725,8 +725,8 @@ public class Tethering {
        intent.setClassName("com.android.settings", "com.android.settings.TetherSettings");
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

        PendingIntent pi = PendingIntent.getActivityAsUser(mContext, 0, intent, 0,
                null, UserHandle.CURRENT);
        PendingIntent pi = PendingIntent.getActivity(
                mContext.createContextAsUser(UserHandle.CURRENT, 0), 0, intent, 0, null);

        Resources r = mContext.getResources();
        final CharSequence title;
@@ -755,17 +755,17 @@ public class Tethering {
                .setContentIntent(pi);
        mLastNotificationId = id;

        notificationManager.notifyAsUser(null, mLastNotificationId,
                mTetheredNotificationBuilder.buildInto(new Notification()), UserHandle.ALL);
        notificationManager.notify(null, mLastNotificationId,
                mTetheredNotificationBuilder.buildInto(new Notification()));
    }

    @VisibleForTesting
    protected void clearTetheredNotification() {
        NotificationManager notificationManager =
                (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
                (NotificationManager) mContext.createContextAsUser(UserHandle.ALL, 0)
                        .getSystemService(Context.NOTIFICATION_SERVICE);
        if (notificationManager != null && mLastNotificationId != 0) {
            notificationManager.cancelAsUser(null, mLastNotificationId,
                    UserHandle.ALL);
            notificationManager.cancel(null, mLastNotificationId);
            mLastNotificationId = 0;
        }
    }
+6 −0
Original line number Diff line number Diff line
@@ -224,6 +224,11 @@ public class TetheringTest {
            if (TelephonyManager.class.equals(serviceClass)) return Context.TELEPHONY_SERVICE;
            return super.getSystemServiceName(serviceClass);
        }

        @Override
        public Context createContextAsUser(UserHandle user, int flags) {
            return mContext;
        }
    }

    public class MockIpServerDependencies extends IpServer.Dependencies {
@@ -432,6 +437,7 @@ public class TetheringTest {
                .thenReturn(true);

        mServiceContext = new TestContext(mContext);
        when(mContext.getSystemService(Context.NOTIFICATION_SERVICE)).thenReturn(null);
        mContentResolver = new MockContentResolver(mServiceContext);
        mContentResolver.addProvider(Settings.AUTHORITY, new FakeSettingsProvider());
        Settings.Global.putInt(mContentResolver, TETHER_ENABLE_LEGACY_DHCP_SERVER, 0);