FileDocCategorySizeDatePackage
SetTimeZonePermissionsTest.javaAPI DocAndroid 5.1 API2403Thu Mar 12 22:22:12 GMT 2015android.app.activity

SetTimeZonePermissionsTest

public class SetTimeZonePermissionsTest extends android.test.AndroidTestCase

Fields Summary
private String[]
mZones
private String
mCurrentZone
private android.app.AlarmManager
mAlarm
Constructors Summary
Methods Summary
protected voidsetUp()

        super.setUp();

        mZones = TimeZone.getAvailableIDs();
        mCurrentZone = TimeZone.getDefault().getID();
        mAlarm = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
    
public voidtestSetTimeZonePermissions()
Verify that non-system processes cannot set the time zone.

        /**
         * Attempt to set several predefined time zones, verifying that the system
         * system default time zone has not actually changed from its prior state
         * after each attempt.
         */
        int max = (mZones.length > 10) ? mZones.length : 10;
        assertTrue("No system-defined time zones - test invalid", max > 0);

        for (int i = 0; i < max; i++) {
            String tz = mZones[i];
            try {
                mAlarm.setTimeZone(tz);
            } catch (SecurityException se) {
                // Expected failure; no need to handle specially since we're
                // about to assert that the test invariant holds: no change
                // to the system time zone.
            }

            String newZone = TimeZone.getDefault().getID();
            assertEquals("AlarmManager.setTimeZone() succeeded despite lack of permission",
                    mCurrentZone,
                    newZone);
        }