Merge "Add new permissions" am: 62ace8c46a am: c0f9b27214
Change-Id: I2114c613729f0d84d773b7e8b58402cda302a8c8
This commit is contained in:
@@ -48,7 +48,7 @@ public class TimeDetector {
|
|||||||
* signal if better signals are available such as those that come from more reliable sources or
|
* signal if better signals are available such as those that come from more reliable sources or
|
||||||
* were determined more recently.
|
* 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) {
|
public void suggestPhoneTime(@NonNull PhoneTimeSuggestion timeSuggestion) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "suggestPhoneTime called: " + timeSuggestion);
|
Log.d(TAG, "suggestPhoneTime called: " + timeSuggestion);
|
||||||
@@ -63,7 +63,7 @@ public class TimeDetector {
|
|||||||
/**
|
/**
|
||||||
* Suggests the user's manually entered current time to the detector.
|
* 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) {
|
public void suggestManualTime(@NonNull ManualTimeSuggestion timeSuggestion) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "suggestManualTime called: " + timeSuggestion);
|
Log.d(TAG, "suggestManualTime called: " + timeSuggestion);
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public class TimeZoneDetector {
|
|||||||
* detector may ignore the signal based on system settings, whether better information is
|
* detector may ignore the signal based on system settings, whether better information is
|
||||||
* available, and so on.
|
* 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) {
|
public void suggestPhoneTimeZone(@NonNull PhoneTimeZoneSuggestion timeZoneSuggestion) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "suggestPhoneTimeZone called: " + timeZoneSuggestion);
|
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
|
* 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.
|
* 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) {
|
public void suggestManualTimeZone(@NonNull ManualTimeZoneSuggestion timeZoneSuggestion) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "suggestManualTimeZone called: " + timeZoneSuggestion);
|
Log.d(TAG, "suggestManualTimeZone called: " + timeZoneSuggestion);
|
||||||
|
|||||||
@@ -2528,17 +2528,17 @@
|
|||||||
<permission android:name="android.permission.READ_WALLPAPER_INTERNAL"
|
<permission android:name="android.permission.READ_WALLPAPER_INTERNAL"
|
||||||
android:protectionLevel="signature|privileged" />
|
android:protectionLevel="signature|privileged" />
|
||||||
|
|
||||||
<!-- ============================================ -->
|
<!-- ===================================================== -->
|
||||||
<!-- Permissions for changing the system clock -->
|
<!-- Permissions for changing the system clock / time zone -->
|
||||||
<!-- ============================================ -->
|
<!-- ===================================================== -->
|
||||||
<eat-comment />
|
<eat-comment />
|
||||||
|
|
||||||
<!-- Allows applications to set the system time.
|
<!-- Allows applications to set the system time directly.
|
||||||
<p>Not for use by third-party applications. -->
|
<p>Not for use by third-party applications. -->
|
||||||
<permission android:name="android.permission.SET_TIME"
|
<permission android:name="android.permission.SET_TIME"
|
||||||
android:protectionLevel="signature|privileged" />
|
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.
|
<p>Not for use by third-party applications.
|
||||||
-->
|
-->
|
||||||
<permission android:name="android.permission.SET_TIME_ZONE"
|
<permission android:name="android.permission.SET_TIME_ZONE"
|
||||||
@@ -2546,6 +2546,20 @@
|
|||||||
android:description="@string/permdesc_setTimeZone"
|
android:description="@string/permdesc_setTimeZone"
|
||||||
android:protectionLevel="signature|privileged" />
|
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 -->
|
<!-- Permissions related to changing status bar -->
|
||||||
<!-- ==================================================== -->
|
<!-- ==================================================== -->
|
||||||
|
|||||||
@@ -42,8 +42,8 @@
|
|||||||
<permission name="android.permission.READ_PRIVILEGED_PHONE_STATE"/>
|
<permission name="android.permission.READ_PRIVILEGED_PHONE_STATE"/>
|
||||||
<permission name="android.permission.READ_SEARCH_INDEXABLES"/>
|
<permission name="android.permission.READ_SEARCH_INDEXABLES"/>
|
||||||
<permission name="android.permission.REBOOT"/>
|
<permission name="android.permission.REBOOT"/>
|
||||||
<permission name="android.permission.SET_TIME"/>
|
|
||||||
<permission name="android.permission.STATUS_BAR"/>
|
<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.TETHER_PRIVILEGED"/>
|
||||||
<permission name="android.permission.USE_RESERVED_DISK"/>
|
<permission name="android.permission.USE_RESERVED_DISK"/>
|
||||||
<permission name="android.permission.USER_ACTIVITY"/>
|
<permission name="android.permission.USER_ACTIVITY"/>
|
||||||
|
|||||||
@@ -155,12 +155,12 @@ applications that come with the platform
|
|||||||
<permission name="android.permission.REGISTER_CALL_PROVIDER"/>
|
<permission name="android.permission.REGISTER_CALL_PROVIDER"/>
|
||||||
<permission name="android.permission.REGISTER_SIM_SUBSCRIPTION"/>
|
<permission name="android.permission.REGISTER_SIM_SUBSCRIPTION"/>
|
||||||
<permission name="android.permission.SEND_RESPOND_VIA_MESSAGE"/>
|
<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.SET_TIME_ZONE"/>
|
||||||
<permission name="android.permission.SHUTDOWN"/>
|
<permission name="android.permission.SHUTDOWN"/>
|
||||||
<permission name="android.permission.START_ACTIVITIES_FROM_BACKGROUND"/>
|
<permission name="android.permission.START_ACTIVITIES_FROM_BACKGROUND"/>
|
||||||
<permission name="android.permission.STATUS_BAR"/>
|
<permission name="android.permission.STATUS_BAR"/>
|
||||||
<permission name="android.permission.STOP_APP_SWITCHES"/>
|
<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_APP_OPS_STATS"/>
|
||||||
<permission name="android.permission.UPDATE_DEVICE_STATS"/>
|
<permission name="android.permission.UPDATE_DEVICE_STATS"/>
|
||||||
<permission name="android.permission.UPDATE_LOCK"/>
|
<permission name="android.permission.UPDATE_LOCK"/>
|
||||||
|
|||||||
@@ -119,10 +119,14 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void enforceSuggestPhoneTimePermission() {
|
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() {
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,10 +18,12 @@ package com.android.server.timedetector;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.doNothing;
|
import static org.mockito.Mockito.doNothing;
|
||||||
|
import static org.mockito.Mockito.doThrow;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -77,6 +79,22 @@ public class TimeDetectorServiceTest {
|
|||||||
mHandlerThread.join();
|
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
|
@Test
|
||||||
public void testSuggestPhoneTime() throws Exception {
|
public void testSuggestPhoneTime() throws Exception {
|
||||||
doNothing().when(mMockContext).enforceCallingPermission(anyString(), any());
|
doNothing().when(mMockContext).enforceCallingPermission(anyString(), any());
|
||||||
@@ -86,13 +104,29 @@ public class TimeDetectorServiceTest {
|
|||||||
mTestHandler.assertTotalMessagesEnqueued(1);
|
mTestHandler.assertTotalMessagesEnqueued(1);
|
||||||
|
|
||||||
verify(mMockContext).enforceCallingPermission(
|
verify(mMockContext).enforceCallingPermission(
|
||||||
eq(android.Manifest.permission.SET_TIME),
|
eq(android.Manifest.permission.SUGGEST_PHONE_TIME_AND_ZONE),
|
||||||
anyString());
|
anyString());
|
||||||
|
|
||||||
mTestHandler.waitForEmptyQueue();
|
mTestHandler.waitForEmptyQueue();
|
||||||
mStubbedTimeDetectorStrategy.verifySuggestPhoneTimeCalled(phoneTimeSuggestion);
|
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
|
@Test
|
||||||
public void testSuggestManualTime() throws Exception {
|
public void testSuggestManualTime() throws Exception {
|
||||||
doNothing().when(mMockContext).enforceCallingOrSelfPermission(anyString(), any());
|
doNothing().when(mMockContext).enforceCallingOrSelfPermission(anyString(), any());
|
||||||
@@ -102,7 +136,7 @@ public class TimeDetectorServiceTest {
|
|||||||
mTestHandler.assertTotalMessagesEnqueued(1);
|
mTestHandler.assertTotalMessagesEnqueued(1);
|
||||||
|
|
||||||
verify(mMockContext).enforceCallingOrSelfPermission(
|
verify(mMockContext).enforceCallingOrSelfPermission(
|
||||||
eq(android.Manifest.permission.SET_TIME),
|
eq(android.Manifest.permission.SUGGEST_MANUAL_TIME_AND_ZONE),
|
||||||
anyString());
|
anyString());
|
||||||
|
|
||||||
mTestHandler.waitForEmptyQueue();
|
mTestHandler.waitForEmptyQueue();
|
||||||
|
|||||||
Reference in New Issue
Block a user