Merge "Add new permissions"

am: 62ace8c46a

Change-Id: I618e2f4a608914d1bf679186880cd358a75a238d
This commit is contained in:
Neil Fuller
2020-01-06 13:02:34 -08:00
committed by android-build-merger
7 changed files with 68 additions and 16 deletions

View File

@@ -48,7 +48,7 @@ public class TimeDetector {
* signal if better signals are available such as those that come from more reliable sources or
* were determined more recently.
*/
@RequiresPermission(android.Manifest.permission.SET_TIME)
@RequiresPermission(android.Manifest.permission.SUGGEST_PHONE_TIME_AND_ZONE)
public void suggestPhoneTime(@NonNull PhoneTimeSuggestion timeSuggestion) {
if (DEBUG) {
Log.d(TAG, "suggestPhoneTime called: " + timeSuggestion);
@@ -63,7 +63,7 @@ public class TimeDetector {
/**
* Suggests the user's manually entered current time to the detector.
*/
@RequiresPermission(android.Manifest.permission.SET_TIME)
@RequiresPermission(android.Manifest.permission.SUGGEST_MANUAL_TIME_AND_ZONE)
public void suggestManualTime(@NonNull ManualTimeSuggestion timeSuggestion) {
if (DEBUG) {
Log.d(TAG, "suggestManualTime called: " + timeSuggestion);

View File

@@ -47,7 +47,7 @@ public class TimeZoneDetector {
* detector may ignore the signal based on system settings, whether better information is
* available, and so on.
*/
@RequiresPermission(android.Manifest.permission.SET_TIME_ZONE)
@RequiresPermission(android.Manifest.permission.SUGGEST_PHONE_TIME_AND_ZONE)
public void suggestPhoneTimeZone(@NonNull PhoneTimeZoneSuggestion timeZoneSuggestion) {
if (DEBUG) {
Log.d(TAG, "suggestPhoneTimeZone called: " + timeZoneSuggestion);
@@ -63,7 +63,7 @@ public class TimeZoneDetector {
* Suggests the current time zone, determined for the user's manually information, to the
* detector. The detector may ignore the signal based on system settings.
*/
@RequiresPermission(android.Manifest.permission.SET_TIME_ZONE)
@RequiresPermission(android.Manifest.permission.SUGGEST_MANUAL_TIME_AND_ZONE)
public void suggestManualTimeZone(@NonNull ManualTimeZoneSuggestion timeZoneSuggestion) {
if (DEBUG) {
Log.d(TAG, "suggestManualTimeZone called: " + timeZoneSuggestion);

View File

@@ -2524,17 +2524,17 @@
<permission android:name="android.permission.READ_WALLPAPER_INTERNAL"
android:protectionLevel="signature|privileged" />
<!-- ============================================ -->
<!-- Permissions for changing the system clock -->
<!-- ============================================ -->
<!-- ===================================================== -->
<!-- Permissions for changing the system clock / time zone -->
<!-- ===================================================== -->
<eat-comment />
<!-- Allows applications to set the system time.
<p>Not for use by third-party applications. -->
<!-- Allows applications to set the system time directly.
<p>Not for use by third-party applications. -->
<permission android:name="android.permission.SET_TIME"
android:protectionLevel="signature|privileged" />
<!-- Allows applications to set the system time zone.
<!-- Allows applications to set the system time zone directly.
<p>Not for use by third-party applications.
-->
<permission android:name="android.permission.SET_TIME_ZONE"
@@ -2542,6 +2542,20 @@
android:description="@string/permdesc_setTimeZone"
android:protectionLevel="signature|privileged" />
<!-- Allows telephony to suggest the time / time zone.
<p>Not for use by third-party applications.
@hide
-->
<permission android:name="android.permission.SUGGEST_PHONE_TIME_AND_ZONE"
android:protectionLevel="signature|telephony" />
<!-- Allows applications like settings to suggest the user's manually chosen time / time zone.
<p>Not for use by third-party applications.
@hide
-->
<permission android:name="android.permission.SUGGEST_MANUAL_TIME_AND_ZONE"
android:protectionLevel="signature" />
<!-- ==================================================== -->
<!-- Permissions related to changing status bar -->
<!-- ==================================================== -->

View File

@@ -42,8 +42,8 @@
<permission name="android.permission.READ_PRIVILEGED_PHONE_STATE"/>
<permission name="android.permission.READ_SEARCH_INDEXABLES"/>
<permission name="android.permission.REBOOT"/>
<permission name="android.permission.SET_TIME"/>
<permission name="android.permission.STATUS_BAR"/>
<permission name="android.permission.SUGGEST_MANUAL_TIME_AND_ZONE"/>
<permission name="android.permission.TETHER_PRIVILEGED"/>
<permission name="android.permission.USE_RESERVED_DISK"/>
<permission name="android.permission.USER_ACTIVITY"/>

View File

@@ -155,12 +155,12 @@ applications that come with the platform
<permission name="android.permission.REGISTER_CALL_PROVIDER"/>
<permission name="android.permission.REGISTER_SIM_SUBSCRIPTION"/>
<permission name="android.permission.SEND_RESPOND_VIA_MESSAGE"/>
<permission name="android.permission.SET_TIME"/>
<permission name="android.permission.SET_TIME_ZONE"/>
<permission name="android.permission.SHUTDOWN"/>
<permission name="android.permission.START_ACTIVITIES_FROM_BACKGROUND"/>
<permission name="android.permission.STATUS_BAR"/>
<permission name="android.permission.STOP_APP_SWITCHES"/>
<permission name="android.permission.SUGGEST_PHONE_TIME_AND_ZONE"/>
<permission name="android.permission.UPDATE_APP_OPS_STATS"/>
<permission name="android.permission.UPDATE_DEVICE_STATS"/>
<permission name="android.permission.UPDATE_LOCK"/>

View File

@@ -119,10 +119,14 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub {
}
private void enforceSuggestPhoneTimePermission() {
mContext.enforceCallingPermission(android.Manifest.permission.SET_TIME, "set time");
mContext.enforceCallingPermission(
android.Manifest.permission.SUGGEST_PHONE_TIME_AND_ZONE,
"suggest phone time and time zone");
}
private void enforceSuggestManualTimePermission() {
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.SET_TIME, "set time");
mContext.enforceCallingOrSelfPermission(
android.Manifest.permission.SUGGEST_MANUAL_TIME_AND_ZONE,
"suggest manual time and time zone");
}
}

View File

@@ -18,10 +18,12 @@ package com.android.server.timedetector;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -77,6 +79,22 @@ public class TimeDetectorServiceTest {
mHandlerThread.join();
}
@Test(expected = SecurityException.class)
public void testSuggestPhoneTime_withoutPermission() {
doThrow(new SecurityException("Mock"))
.when(mMockContext).enforceCallingPermission(anyString(), any());
PhoneTimeSuggestion phoneTimeSuggestion = createPhoneTimeSuggestion();
try {
mTimeDetectorService.suggestPhoneTime(phoneTimeSuggestion);
fail();
} finally {
verify(mMockContext).enforceCallingPermission(
eq(android.Manifest.permission.SUGGEST_PHONE_TIME_AND_ZONE),
anyString());
}
}
@Test
public void testSuggestPhoneTime() throws Exception {
doNothing().when(mMockContext).enforceCallingPermission(anyString(), any());
@@ -86,13 +104,29 @@ public class TimeDetectorServiceTest {
mTestHandler.assertTotalMessagesEnqueued(1);
verify(mMockContext).enforceCallingPermission(
eq(android.Manifest.permission.SET_TIME),
eq(android.Manifest.permission.SUGGEST_PHONE_TIME_AND_ZONE),
anyString());
mTestHandler.waitForEmptyQueue();
mStubbedTimeDetectorStrategy.verifySuggestPhoneTimeCalled(phoneTimeSuggestion);
}
@Test(expected = SecurityException.class)
public void testSuggestManualTime_withoutPermission() {
doThrow(new SecurityException("Mock"))
.when(mMockContext).enforceCallingOrSelfPermission(anyString(), any());
ManualTimeSuggestion manualTimeSuggestion = createManualTimeSuggestion();
try {
mTimeDetectorService.suggestManualTime(manualTimeSuggestion);
fail();
} finally {
verify(mMockContext).enforceCallingOrSelfPermission(
eq(android.Manifest.permission.SUGGEST_MANUAL_TIME_AND_ZONE),
anyString());
}
}
@Test
public void testSuggestManualTime() throws Exception {
doNothing().when(mMockContext).enforceCallingOrSelfPermission(anyString(), any());
@@ -102,7 +136,7 @@ public class TimeDetectorServiceTest {
mTestHandler.assertTotalMessagesEnqueued(1);
verify(mMockContext).enforceCallingOrSelfPermission(
eq(android.Manifest.permission.SET_TIME),
eq(android.Manifest.permission.SUGGEST_MANUAL_TIME_AND_ZONE),
anyString());
mTestHandler.waitForEmptyQueue();