OSDN Git Service

Revert "Move backup classes to nonlib"
[android-x86/packages-apps-Taskbar.git] / app / src / playstore / java / com / farmerbb / taskbar / receiver / SendSettingsReceiver.java
1 /* Copyright 2016 Braden Farmer
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 package com.farmerbb.taskbar.receiver;
17
18 import android.content.BroadcastReceiver;
19 import android.content.Context;
20 import android.content.Intent;
21 import android.net.Uri;
22 import androidx.core.content.FileProvider;
23
24 import com.farmerbb.taskbar.BuildConfig;
25 import com.farmerbb.taskbar.backup.BackupUtils;
26 import com.farmerbb.taskbar.backup.IntentBackupAgent;
27 import com.farmerbb.taskbar.util.U;
28
29 import java.io.File;
30
31 public class SendSettingsReceiver extends BroadcastReceiver {
32     @Override
33     public void onReceive(Context context, Intent intent) {
34         // Ignore this broadcast if this is the paid version
35         if(context.getPackageName().equals(BuildConfig.BASE_APPLICATION_ID)) {
36             Intent sendSettingsIntent = new Intent("com.farmerbb.taskbar.SEND_SETTINGS");
37             sendSettingsIntent.setPackage(BuildConfig.PAID_APPLICATION_ID);
38
39             BackupUtils.backup(context, new IntentBackupAgent(sendSettingsIntent));
40
41             // Get custom start button image
42             File file = new File(context.getFilesDir() + "/tb_images", "custom_image");
43             if(file.exists() && U.isPlayStoreRelease(context, BuildConfig.PAID_APPLICATION_ID)) {
44                 Uri uri = FileProvider.getUriForFile(context, context.getPackageName() + ".fileprovider", file);
45                 context.grantUriPermission(BuildConfig.PAID_APPLICATION_ID, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
46                 sendSettingsIntent.putExtra("custom_image", uri);
47             }
48
49             // Finally, send the broadcast
50             context.sendBroadcast(sendSettingsIntent);
51         }
52     }
53 }