packages/apps/Settings
修订版 | 4c16ad5abf51444891ff43947bafcbae3f3379c4 (tree) |
---|---|
时间 | 2018-11-20 14:00:03 |
作者 | TreeHugger Robot <treehugger-gerrit@goog...> |
Commiter | Android (Google) Code Review |
Merge "Hide quicksetting tile for dev options when it's turned off" into pi-dev
@@ -16,7 +16,9 @@ | ||
16 | 16 | |
17 | 17 | package com.android.settings.development.qstile; |
18 | 18 | |
19 | +import android.content.ComponentName; | |
19 | 20 | import android.content.Context; |
21 | +import android.content.pm.PackageManager; | |
20 | 22 | import android.os.IBinder; |
21 | 23 | import android.os.Parcel; |
22 | 24 | import android.os.RemoteException; |
@@ -26,6 +28,7 @@ import android.provider.Settings; | ||
26 | 28 | import android.service.quicksettings.Tile; |
27 | 29 | import android.service.quicksettings.TileService; |
28 | 30 | import android.support.annotation.VisibleForTesting; |
31 | +import android.util.EventLog; | |
29 | 32 | import android.util.Log; |
30 | 33 | import android.view.IWindowManager; |
31 | 34 | import android.view.ThreadedRenderer; |
@@ -34,6 +37,8 @@ import android.view.WindowManagerGlobal; | ||
34 | 37 | import android.widget.Toast; |
35 | 38 | |
36 | 39 | import com.android.internal.app.LocalePicker; |
40 | +import com.android.internal.statusbar.IStatusBarService; | |
41 | +import com.android.settingslib.development.DevelopmentSettingsEnabler; | |
37 | 42 | import com.android.settingslib.development.SystemPropPoker; |
38 | 43 | |
39 | 44 | public abstract class DevelopmentTiles extends TileService { |
@@ -50,7 +55,33 @@ public abstract class DevelopmentTiles extends TileService { | ||
50 | 55 | } |
51 | 56 | |
52 | 57 | public void refresh() { |
53 | - getQsTile().setState(isEnabled() ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE); | |
58 | + final int state; | |
59 | + if (!DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(this)) { | |
60 | + // Reset to disabled state if dev option is off. | |
61 | + if (isEnabled()) { | |
62 | + setIsEnabled(false); | |
63 | + SystemPropPoker.getInstance().poke(); | |
64 | + } | |
65 | + final ComponentName cn = new ComponentName(getPackageName(), getClass().getName()); | |
66 | + try { | |
67 | + getPackageManager().setComponentEnabledSetting( | |
68 | + cn, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, | |
69 | + PackageManager.DONT_KILL_APP); | |
70 | + final IStatusBarService statusBarService = IStatusBarService.Stub.asInterface( | |
71 | + ServiceManager.checkService(Context.STATUS_BAR_SERVICE)); | |
72 | + if (statusBarService != null) { | |
73 | + EventLog.writeEvent(0x534e4554, "117770924"); // SaftyNet | |
74 | + statusBarService.remTile(cn); | |
75 | + } | |
76 | + } catch (RemoteException e) { | |
77 | + Log.e(TAG, "Failed to modify QS tile for component " + | |
78 | + cn.toString(), e); | |
79 | + } | |
80 | + state = Tile.STATE_UNAVAILABLE; | |
81 | + } else { | |
82 | + state = isEnabled() ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE; | |
83 | + } | |
84 | + getQsTile().setState(state); | |
54 | 85 | getQsTile().updateTile(); |
55 | 86 | } |
56 | 87 |
@@ -241,4 +272,4 @@ public abstract class DevelopmentTiles extends TileService { | ||
241 | 272 | } |
242 | 273 | } |
243 | 274 | } |
244 | -} | |
\ No newline at end of file | ||
275 | +} |
@@ -0,0 +1,71 @@ | ||
1 | +/* | |
2 | + * Copyright (C) 2018 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.settings.development.qstile; | |
18 | + | |
19 | +import static com.google.common.truth.Truth.assertThat; | |
20 | +import static org.mockito.Mockito.doReturn; | |
21 | +import static org.mockito.Mockito.spy; | |
22 | +import static org.mockito.Mockito.verify; | |
23 | + | |
24 | +import android.content.ComponentName; | |
25 | +import android.content.pm.PackageManager; | |
26 | +import android.service.quicksettings.Tile; | |
27 | + | |
28 | +import com.android.settings.testutils.SettingsRobolectricTestRunner; | |
29 | +import com.android.settingslib.development.DevelopmentSettingsEnabler; | |
30 | + | |
31 | +import org.junit.Before; | |
32 | +import org.junit.Test; | |
33 | +import org.junit.runner.RunWith; | |
34 | +import org.mockito.Mock; | |
35 | +import org.mockito.MockitoAnnotations; | |
36 | +import org.robolectric.Robolectric; | |
37 | + | |
38 | +@RunWith(SettingsRobolectricTestRunner.class) | |
39 | +public class DevelopmentTilesTest { | |
40 | + | |
41 | + @Mock | |
42 | + private Tile mTile; | |
43 | + @Mock | |
44 | + private PackageManager mPackageManager; | |
45 | + | |
46 | + private DevelopmentTiles mService; | |
47 | + | |
48 | + @Before | |
49 | + public void setUp() { | |
50 | + MockitoAnnotations.initMocks(this); | |
51 | + mService = spy(Robolectric.setupService(DevelopmentTiles.ShowLayout.class)); | |
52 | + doReturn(mTile).when(mService).getQsTile(); | |
53 | + } | |
54 | + | |
55 | + @Test | |
56 | + public void refresh_devOptionIsDisabled_shouldResetTileValue() { | |
57 | + final ComponentName cn = new ComponentName( | |
58 | + mService.getPackageName(), mService.getClass().getName()); | |
59 | + doReturn(mPackageManager).when(mService).getPackageManager(); | |
60 | + | |
61 | + DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(mService, false); | |
62 | + mService.setIsEnabled(true); | |
63 | + | |
64 | + mService.refresh(); | |
65 | + | |
66 | + verify(mPackageManager).setComponentEnabledSetting(cn, | |
67 | + PackageManager.COMPONENT_ENABLED_STATE_DISABLED, | |
68 | + PackageManager.DONT_KILL_APP); | |
69 | + assertThat(mService.isEnabled()).isFalse(); | |
70 | + } | |
71 | +} |