Home | History | Annotate | Download | only in settings
      1 /*
      2  * Copyright (C) 2016 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 com.android.settings;
     18 
     19 import android.app.Activity;
     20 import android.app.backup.BackupManager;
     21 import android.app.backup.IBackupManager;
     22 import android.content.Context;
     23 import android.content.Intent;
     24 import android.os.Bundle;
     25 import android.os.ServiceManager;
     26 import android.os.UserHandle;
     27 import android.text.TextUtils;
     28 import android.util.Log;
     29 
     30 import com.android.settings.R;
     31 
     32 import java.net.URISyntaxException;
     33 
     34 /**
     35  * A trampoline activity used to launch the configured Backup activity.
     36  * This activity used the theme NoDisplay to minimize the flicker that might be seen for the launch-
     37  * finsih transition.
     38  */
     39 public class BackupSettingsActivity extends Activity {
     40     private static final String TAG = "BackupSettingsActivity";
     41 
     42     @Override
     43     public void onCreate(Bundle savedInstanceState) {
     44         super.onCreate(savedInstanceState);
     45         String backup = getResources().getString(R.string.config_backup_settings_intent);
     46         if (!TextUtils.isEmpty(backup)) {
     47             try {
     48                 Intent intent = Intent.parseUri(backup, 0);
     49                 if (intent.resolveActivity(getPackageManager()) != null) {
     50                     // use startActivityForResult to let the activity check the caller signature
     51                     IBackupManager bmgr = IBackupManager.Stub.asInterface(
     52                             ServiceManager.getService(Context.BACKUP_SERVICE));
     53                     boolean backupOkay;
     54                     try {
     55                         backupOkay = bmgr.isBackupServiceActive(UserHandle.myUserId());
     56                     } catch (Exception e) {
     57                         // things go wrong talking to the backup system => ignore and
     58                         // pass the default 'false' as the "backup is a thing?" state.
     59                         backupOkay = false;
     60                     }
     61                     intent.putExtra(BackupManager.EXTRA_BACKUP_SERVICES_AVAILABLE, backupOkay);
     62                     startActivityForResult(intent, -1);
     63                 } else {
     64                     Log.e(TAG, "Backup component not found!");
     65                 }
     66             } catch (URISyntaxException e) {
     67                 Log.e(TAG, "Invalid backup component URI!", e);
     68             }
     69         }
     70         finish();
     71     }
     72 }