1 /* 2 * Copyright (C) 2017 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 android.app.timezone; 18 19 import android.content.Context; 20 import android.content.Intent; 21 import android.os.ParcelFileDescriptor; 22 import android.os.UserHandle; 23 24 /** 25 * Constants related to the contract between the Android system and the privileged time zone updater 26 * application. 27 * 28 * @hide 29 */ 30 public final class RulesUpdaterContract { 31 32 /** 33 * The system permission possessed by the Android system that allows it to trigger time zone 34 * update checks. The updater should be configured to require this permission when registering 35 * for {@link #ACTION_TRIGGER_RULES_UPDATE_CHECK} intents. 36 */ 37 public static final String TRIGGER_TIME_ZONE_RULES_CHECK_PERMISSION = 38 android.Manifest.permission.TRIGGER_TIME_ZONE_RULES_CHECK; 39 40 /** 41 * The system permission possessed by the time zone rules updater app that allows it to update 42 * device time zone rules. The Android system requires this permission for calls made to 43 * {@link RulesManager}. 44 */ 45 public static final String UPDATE_TIME_ZONE_RULES_PERMISSION = 46 android.Manifest.permission.UPDATE_TIME_ZONE_RULES; 47 48 /** 49 * The action of the intent that the Android system will broadcast. The intent will be targeted 50 * at the configured updater application's package meaning the term "broadcast" only loosely 51 * applies. 52 */ 53 public static final String ACTION_TRIGGER_RULES_UPDATE_CHECK = 54 "com.android.intent.action.timezone.TRIGGER_RULES_UPDATE_CHECK"; 55 56 /** 57 * The extra containing the {@code byte[]} that should be passed to 58 * {@link RulesManager#requestInstall(ParcelFileDescriptor, byte[], Callback)}, 59 * {@link RulesManager#requestUninstall(byte[], Callback)} and 60 * {@link RulesManager#requestNothing(byte[], boolean)} methods when the 61 * {@link #ACTION_TRIGGER_RULES_UPDATE_CHECK} intent has been processed. 62 */ 63 public static final String EXTRA_CHECK_TOKEN = 64 "com.android.intent.extra.timezone.CHECK_TOKEN"; 65 66 /** 67 * Creates an intent that would trigger a time zone rules update check. 68 */ createUpdaterIntent(String updaterPackageName)69 public static Intent createUpdaterIntent(String updaterPackageName) { 70 Intent intent = new Intent(RulesUpdaterContract.ACTION_TRIGGER_RULES_UPDATE_CHECK); 71 intent.setPackage(updaterPackageName); 72 intent.setFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); 73 return intent; 74 } 75 76 /** 77 * Broadcasts an {@link #ACTION_TRIGGER_RULES_UPDATE_CHECK} intent with the 78 * {@link #EXTRA_CHECK_TOKEN} that triggers an update check, including the required receiver 79 * permission. 80 */ sendBroadcast(Context context, String updaterAppPackageName, byte[] checkTokenBytes)81 public static void sendBroadcast(Context context, String updaterAppPackageName, 82 byte[] checkTokenBytes) { 83 Intent intent = createUpdaterIntent(updaterAppPackageName); 84 intent.putExtra(EXTRA_CHECK_TOKEN, checkTokenBytes); 85 context.sendBroadcastAsUser( 86 intent, UserHandle.SYSTEM, 87 RulesUpdaterContract.UPDATE_TIME_ZONE_RULES_PERMISSION); 88 } 89 } 90