• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.wallpaper.backup;
17 
18 import android.annotation.SuppressLint;
19 import android.app.WallpaperManager;
20 import android.content.BroadcastReceiver;
21 import android.content.Context;
22 import android.content.Intent;
23 
24 import com.android.wallpaper.module.Injector;
25 import com.android.wallpaper.module.InjectorProvider;
26 import com.android.wallpaper.module.WallpaperPreferences;
27 
28 /**
29  * Generates hash codes for currently set static image wallpapers on N+ devices where they are
30  * missing because older versions of the app did not generate and set them.
31  * <p>
32  * Static image wallpaper hash codes are necessary on N+ devices for the purposes of backup &
33  * restore because N+ WallpaperManager integer IDs are local to physical devices and not backed up
34  * and restored on the framework side.
35  */
36 @SuppressLint("ServiceCast")
37 public class MissingHashCodeGenerator extends BroadcastReceiver {
38 
39     @Override
onReceive(Context context, Intent intent)40     public void onReceive(Context context, Intent intent) {
41         String action = intent.getAction();
42         if (action == null  || !action.equals(Intent.ACTION_MY_PACKAGE_REPLACED)) {
43             return;
44         }
45 
46         WallpaperManager wallpaperManager = WallpaperManager.getInstance(context);
47 
48         // Make this receiver a no-op if running in the context of profile where wallpapers are not
49         // supported.
50         if (!wallpaperManager.isWallpaperSupported()) {
51             return;
52         }
53 
54         Injector injector = InjectorProvider.getInjector();
55         WallpaperPreferences wallpaperPreferences = injector.getPreferences(context);
56         // Delegate the longer-running work of generating missing hash codes to a JobScheduler job if
57         // there's no hash codes saved.
58         if (wallpaperPreferences.getHomeWallpaperHashCode() != 0
59                 && wallpaperPreferences.getLockWallpaperHashCode() != 0) {
60             return;
61         }
62 
63         MissingHashCodeGeneratorJobService.schedule(context);
64     }
65 }
66