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;
// }
//}
相關文章
- Provider Hosted App中使用JOM問題IDEAPP
- Server-side rendering for any React app on any FaaS providerServerIDEReactAPP
- java.lang.NoSuchMethodException: tk.mybatis.mapper.provider.ExampleProvider.「init」()JavaExceptionMyBatisAPPIDE
- Document Provider ExtensionsIDE
- Download ProviderIDE
- SharePoint 2013 開發——Provider-hosted APP準備工作IDEAPP
- provider之selectorIDE
- Laravel 2.3 Service ProviderLaravelIDE
- 【SQLServer】The provider supports the interfaceSQLServerIDE
- Oracle Data Provider for .NETOracleIDE
- angularJS中ProviderAngularJSIDE
- SharePoint 2013 開發——開發並部署Provider-hosted APPIDEAPP
- Flutter狀態管理Provider(三)基於Provider的程式碼框架FlutterIDE框架
- 自己寫一個ProviderIDE
- Flutter Provider使用指南FlutterIDE
- Flutter Provider and Streams [翻譯]FlutterIDE
- Android中Content ProviderAndroidIDE
- 域滲透——Security Support ProviderIDE
- Android Content Provider SecurityAndroidIDE
- Flutter Provider 3.0實戰教程FlutterIDE
- Flutter Provider狀態管理框架FlutterIDE框架
- Laravel Service Provider 概念詳解LaravelIDE
- SharePoint 2013 Apps TokenHelper SharePointContext OAuth Provider-Hosted App (抄襲,測試 csc.rsp 用)APPContextOAuthIDE
- Flutter | 狀態管理指南篇——ProviderFlutterIDE
- Flutter狀態管理-04-ProviderFlutterIDE
- Angular No provider for EffectsRootModule錯誤訊息AngularIDE
- Vapor 2.0 - MySQL提供程式(MySQL Provider)VaporMySqlIDE
- SAP API management portal - 如何建立API providerAPIIDE
- 從零開始的Flutter之旅: ProviderFlutterIDE
- Flutter Provider 之 FutureProvider 與 StreamProviderFlutterIDE
- flutter狀態管理provider的基本使用FlutterIDE
- Flutter狀態管理Provider,簡單上手FlutterIDE
- provider的使用以及優化心得IDE優化
- react-redux的Provider和connectReactReduxIDE
- android: failed to find provider info for downloadsAndroidAIIDE
- [譯]Flutter - 使用Provider實現狀態管理FlutterIDE
- 善用 Provider 榨乾 Flutter 最後一點效能IDEFlutter
- Flutter狀態管理Provider(二)過程分析FlutterIDE