provider for back&restore app datya
back resotre app data, inf
///**
//1. 概述:由客戶端自行查詢應用並展示給使用者,使用者選擇需要備份或還原的應用後,依次通過 provider insert 介面進行備份還原的操作(每一個應用執行一次 insert)
//2. Provider URI:content://com.ll.SecurityCenter.backuprestore/app
//3. ContentValues格式:
//package_name: 需要備份或還原應用的包名
//patch:需要備份或還原的內容存放路徑
//data:0 為不需要備份或還原應用資料,1 為需要備份或還原應用資料
//action:0為備份,1 為還原
//4. 舉例:
//item = new ContentValues();
//item.put("package_name","com.meitu.meiyancamera");
//item.put("path", "/sdcard/zzzzz/");
//**/
//
//public class AppProvider extends ContentProvider {
//
// private static final String TAG = "AppProvider";
// private static final UriMatcher mMatcher;
// //AUTHORITY
// private static final String AUTHORITY = "com.ll.SecurityCenter.backuprestore";
// private static final String APP_DATA_PATH_CFG_FILE = "/sdcard/.appDataPath.cfg";
// private static final String BACKUP_APP_DATA_CFG_FILE = "/sdcard/.backupAppData.cfg";
// private static final String RESTORE_APP_DATA_CFG_FILE = "/sdcard/.restoreAppData.cfg";
// private static final String PROGRESS_FLAG_FILE = "/sdcard/.progressFlagFile";
// public static final int SUCCESS = 0;
// public static final int ERR = 1;
// public static final int UNKNOWN_ERR = -1;
//
// private static final int AppBackupRestore = 1;
//
// static {
// mMatcher = new UriMatcher(UriMatcher.NO_MATCH);
// mMatcher.addURI(AUTHORITY, "app", AppBackupRestore); //com.ll.SecurityCenter.backuprestore/app
// }
//
// //================================主要操作程式碼=========================================== start
// @Override
// public Uri insert(Uri uri, ContentValues values) {
// Uri result = null;
// switch (mMatcher.match(uri)) {
//
// // 對應用程式備份恢復的操作
// case AppBackupRestore:
// String action = (String) values.get("action");
// String data = (String) values.get("data");
// Log.d(TAG, "insert action:" + action + ", data :" + data);
// //backup
// if (action.equals("0")) {
// result = doAppBackup(values);
// }
// //restore
// else if (action.equals("1")) {
// result = doAppRestore(values);
// }
// break;
//
// default:
// break;
// }
// return result;
// }
//
// public Uri doAppBackup(ContentValues values){
// String backupPatch = (String) values.get("path");
// String data = (String) values.get("data");
// String packageName = (String) values.get("package_name");
// Log.d(TAG, "packageName : "+ packageName + ", backupPatch:" + backupPatch);
// if(data.equals("1")){
// File pathFile1 = new File(APP_DATA_PATH_CFG_FILE);
// if (pathFile1.exists()) {
// pathFile1.delete();
// }
// File packageFile1 = new File(BACKUP_APP_DATA_CFG_FILE);
// if (packageFile1.exists()) {
// packageFile1.delete();
// }
// FileOutputStream outPath = null;
// FileOutputStream outPackage = null;
// try {
// File pathFile = new File(APP_DATA_PATH_CFG_FILE);
// File packageFile = new File(BACKUP_APP_DATA_CFG_FILE);
// outPath = new FileOutputStream(pathFile, true);
// outPackage = new FileOutputStream(packageFile, true);
// String useablePath = backupPatch;
// if (useablePath.startsWith("/storage/emulated/0") ) {
// useablePath = useablePath.replaceFirst("/storage/emulated/0","/sdcard");
// }
// outPath.write(useablePath.getBytes());
// Log.d(TAG, "useablePath = " + useablePath + ", PackageName = " + packageName);
// outPackage.write(packageName.getBytes());
// outPackage.write('\n');
//
// } catch (Exception e) {
// Log.d(TAG, "backupOneAPP PackageName:"+ packageName + "error:" + e.toString());
// return null;
// } finally {
// if (null != outPath) {
// try {
// outPath.flush();
// outPath.close();
// } catch (Exception e) {
// outPath = null;
// }
// }
// if (null != outPackage) {
// try {
// outPackage.flush();
// outPackage.close();
// } catch (Exception e) {
// outPackage = null;
// }
// }
// }
// SystemService.start("backupAppData");
// boolean whileFlag = true;
// while (whileFlag) {
// try {
// Thread.sleep(1000);
// } catch (Exception e) {
// Log.e(TAG, "InterruptedException :" + e);
// }
// File flagFile = new File(PROGRESS_FLAG_FILE);
// if (!flagFile.exists()) {
// whileFlag = false;
// }
// flagFile = null;
// }
// //File apkFile = new File(backupDir + "/" + appin.packageName+ ".apk");
// File dataFile = new File(backupPatch + "/" + packageName+ ".tar");
// if(dataFile.exists()){
// return Uri.fromFile(dataFile);
// }else{
// return null;
// }
// }else{
// return null;
// }
// }
//
// public Uri doAppRestore(ContentValues values){
// String restorePatch = (String) values.get("path");
// String data = (String) values.get("data");
// String packageName = (String) values.get("package_name");
// Log.d(TAG, "restorePatch = " + restorePatch + ", data = " + data + ", packageName:"+ packageName);
// Uri result = null;
// if(data.equals("1")){
// //restore appdata
// result = restoreAppData(restorePatch,packageName);
// }else if(data.equals("0")){
// //restore app
// String fullApkName = restorePatch + "/"+ packageName + ".apk";
// result =installApk(fullApkName);
// }
// return result;
// }
//
// private Uri installApk(String fullApkName) {
// Uri result = Uri.parse(fullApkName);
// Log.d(TAG, "Install App: " + fullApkName);
// String newcommand = "pm install -r -i "+ "com.android.packageinstaller"+ " --user 0 "+ fullApkName;
// Process process;
// try {
// process = Runtime.getRuntime().exec(newcommand);
// process.waitFor();
// } catch (IOException e) {
// result = null;
// Log.d(TAG, "install apk Name:"+ fullApkName + ", IOException:"+ e.toString());
// } catch (Exception e) {
// result = null;
// Log.d(TAG, "install apk Name:"+ fullApkName + ", Exception:"+ e.toString());
// }
// Log.d(TAG, "install result: " + result);
// return result;
// }
//
// private Uri restoreAppData(String restorePath, String packageName) {
// Uri ret = Uri.parse(packageName);
// File pathFile = new File(APP_DATA_PATH_CFG_FILE);
// if(pathFile.exists()){
// pathFile.delete();
// }
// File packageFile = new File(RESTORE_APP_DATA_CFG_FILE);
// if(packageFile.exists()){
// packageFile.delete();
// }
// FileOutputStream outPath = null;
// FileOutputStream outPackage = null;
// try {
// outPath = new FileOutputStream(APP_DATA_PATH_CFG_FILE, true);
// outPackage = new FileOutputStream(RESTORE_APP_DATA_CFG_FILE, true);
// String useablePath = restorePath;
// if (restorePath.startsWith("/storage/emulated/0")) {
// useablePath = restorePath.replaceFirst("/storage/emulated/0", "/sdcard");
// }
// outPath.write(useablePath.getBytes());
// outPackage.write(packageName.getBytes());
// outPackage.write('\n');
// Log.d(TAG, " RECOVERAPPDATA------->:"+ packageName);
// SystemService.start("recoverAppData");
// boolean whileFlag = true;
// while (whileFlag) {
// try {
// Thread.sleep(1500);
// } catch (InterruptedException e) {
// ret = null;
// Log.e(TAG, "InterruptedException :" + e);
// break;
// }
// File flagFile = new File(PROGRESS_FLAG_FILE);
// if (!flagFile.exists()) {
// whileFlag = false;
// }
// flagFile = null;
// }
// } catch (Exception e) {
// ret = null;
// } finally {
// if (null != outPath) {
// try {
// outPath.flush();
// outPath.close();
// } catch (IOException e) {
// }
// }
// if (null != outPackage) {
// try {
// outPackage.flush();
// outPackage.close();
// } catch (IOException e) {
// }
// }
// }
// return ret;
// }
// //================================主要操作程式碼======================================================== end
//
//
//
// @Override
// public boolean onCreate() {
// return true;
// }
//
// @Override
// public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,String sortOrder) {
// return null ;
// }
//
// @Override
// public int delete(Uri uri, String selection, String[] selectionArgs) {
// return 0;
// }
//
// @Override
// public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
// return 0;
// }
//
// @Override
// public String getType(Uri uri) {
// return null;
// }
//}
相關文章
- Server-side rendering for any React app on any FaaS providerServerIDEReactAPP
- provider之selectorIDE
- Android中Content ProviderAndroidIDE
- Android Content Provider SecurityAndroidIDE
- Laravel 2.3 Service ProviderLaravelIDE
- Flutter狀態管理Provider(三)基於Provider的程式碼框架FlutterIDE框架
- Flutter Provider使用指南FlutterIDE
- 自己寫一個ProviderIDE
- Flutter Provider and Streams [翻譯]FlutterIDE
- Flutter Provider狀態管理框架FlutterIDE框架
- Flutter Provider 之 FutureProvider 與 StreamProviderFlutterIDE
- 域滲透——Security Support ProviderIDE
- Flutter Provider 3.0實戰教程FlutterIDE
- Angular No provider for EffectsRootModule錯誤訊息AngularIDE
- Flutter | 狀態管理指南篇——ProviderFlutterIDE
- Flutter 狀態管理之 ChangeNotifierProvider(Provider)FlutterIDE
- Flutter狀態管理-04-ProviderFlutterIDE
- SAP API management portal - 如何建立API providerAPIIDE
- flutter狀態管理provider的基本使用FlutterIDE
- 從零開始的Flutter之旅: ProviderFlutterIDE
- Flutter狀態管理Provider(四) Selector使用FlutterIDE
- Flutter狀態管理Provider,簡單上手FlutterIDE
- angular原始碼剖析之Provider系列--QProviderAngular原始碼IDE
- angular原始碼剖析之Provider系列--CacheFactoryProviderAngular原始碼IDE
- provider的使用以及優化心得IDE優化
- jenkins中使用Config File Provider Plugin(Config File Provider)外掛靈活配置maven多settings.xml檔案JenkinsIDEPluginMavenXML
- path_provider 編譯錯誤指導IDE編譯
- keycloak~對框架中提供的Provider總結框架IDE
- Flutter 狀態管理框架 Provider 和 Get 分析Flutter框架IDE
- 善用 Provider 榨乾 Flutter 最後一點效能IDEFlutter
- Flutter 全域性狀態管理之 Provider 初探FlutterIDE
- Flutter狀態管理之Provider的理解使用FlutterIDE
- 使用 Provider 管理 Flutter 應用狀態 (下)IDEFlutter
- 使用 Provider 管理 Flutter 應用狀態 (上)IDEFlutter
- Flutter狀態管理Provider(二)過程分析FlutterIDE
- Flutter狀態管理Provider(一) 簡易使用FlutterIDE
- [譯]Flutter - 使用Provider實現狀態管理FlutterIDE
- [譯]在底部導航欄裡使用 ProviderIDE