最新动态
设置-安全-手机加密功能讲解加密手机「设置-安全-手机加密功能讲解」
2025-04-02 12:36  浏览:80
一、加密的几种状态


http://osxr.org/android/source/frameworks/base/core/java/android/app/admin/DevicePolicyManager.java#1142 




1117      * Result code for {@link #setStorageEncryption} and {@link #getStorageEncryptionStatus}:
1118      * indicating that encryption is not supported.
1119      */
1120     public static final int ENCRYPTION_STATUS_UNSUPPORTED = 0;
1121 
1122    
1126     public static final int ENCRYPTION_STATUS_INACTIVE = 1;
1127 
1128    
1136     public static final int ENCRYPTION_STATUS_ACTIVATING = 2;
1137 
1138    
1142     public static final int ENCRYPTION_STATUS_ACTIVE = 3;




二 、service的调用


http://osxr.org/android/source/frameworks/base/services/java/com/android/server/DevicePolicyManagerService.java#2029 




2023    
2029     private int getEncryptionStatus() {
2030         String status = SystemProperties.get("ro.crypto.state", "unsupported");
2031         if ("encrypted".equalsIgnoreCase(status)) {
2032             return DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE;
2033         } else if ("unencrypted".equalsIgnoreCase(status)) {
2034             return DevicePolicyManager.ENCRYPTION_STATUS_INACTIVE;
2035         } else {
2036             return DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED;
2037         }
2038     }
2039 




三、最后调用 


http://osxr.org/android/source/frameworks/base/services/java/com/android/server/DevicePolicyManagerService.java#2029
2005    
2008     public int getStorageEncryptionStatus() {
2009         return getEncryptionStatus();


2010     }






四、settings的使用(一


http://osxr.org/android/source/packages/apps/Settings/src/com/android/settings/SecuritySettings.java#0145  


0140         // Add options for device encryption
0141         DevicePolicyManager dpm =
0142                 (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
0143 
0144         if (UserId.myUserId() == 0) {
0145             switch (dpm.getStorageEncryptionStatus()) {
0146             case DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE:
0147                 // The device is currently encrypted.
0148                 addPreferencesFromResource(R.xml.security_settings_encrypted);
0149                 break;
0150             case DevicePolicyManager.ENCRYPTION_STATUS_INACTIVE:
0151                 // This device supports encryption but isn't encrypted.
0152                 addPreferencesFromResource(R.xml.security_settings_unencrypted);
0153                 break;
0154             }
0155         }






四、setting的使用(二




0017 package com.android.settings;
0018 
0019 import android.app.Activity;
0020 import android.app.Fragment;
0021 import android.app.StatusBarManager;
0022 import android.content.Context;
0023 import android.content.Intent;
0024 import android.os.Bundle;
0025 import android.os.Handler;
0026 import android.os.IBinder;
0027 import android.os.ServiceManager;
0028 import android.os.storage.IMountService;
0029 import android.util.Log;
0030 import android.view.LayoutInflater;
0031 import android.view.View;
0032 import android.view.ViewGroup;
0033 import android.widget.Button;
0034 
0035 public class CryptKeeperConfirm extends Fragment {
0036 
0037     public static class Blank extends Activity {
0038         private Handler mHandler = new Handler();
0039 
0040         @Override
0041         public void onCreate(Bundle savedInstanceState) {
0042             super.onCreate(savedInstanceState);
0043 
0044             setContentView(R.layout.crypt_keeper_blank);
0045 
0046             if (Utils.isMonkeyRunning()) {
0047                 finish();
0048             }
0049 
0050             StatusBarManager sbm = (StatusBarManager) getSystemService(Context.STATUS_BAR_SERVICE);
0051             sbm.disable(StatusBarManager.DISABLE_EXPAND
0052                     | StatusBarManager.DISABLE_NOTIFICATION_ICONS
0053                     | StatusBarManager.DISABLE_NOTIFICATION_alertS
0054                     | StatusBarManager.DISABLE_SYSTEM_INFO
0055                     | StatusBarManager.DISABLE_HOME
0056                     | StatusBarManager.DISABLE_RECENT
0057                     | StatusBarManager.DISABLE_BACK);
0058 
0059             // Post a delayed message in 700 milliseconds to enable encryption.
0060             // NOTE: The animation on this activity is set for 500 milliseconds
0061             // I am giving it a little extra time to complete.
0062             mHandler.postDelayed(new Runnable() {
0063                 public void run() {
0064                     IBinder service = ServiceManager.getService("mount");
0065                     if (service == null) {
0066                         Log.e("CryptKeeper", "Failed to find the mount service");
0067                         finish();
0068                         return;
0069                     }
0070 
0071                     IMountService mountService = IMountService.Stub.asInterface(service);
0072                     try {
0073                         Bundle args = getIntent().getExtras();
0074                         mountService.encryptStorage(args.getString("password"));
0075                     } catch (Exception e) {
0076                         Log.e("CryptKeeper", "Error while encrypting...", e);
0077                     }
0078                 }
0079             }, 700);
0080         }
0081     }
0082 
0083     private View mContentView;
0084     private Button mFinalButton;
0085     private Button.onClickListener mFinalClickListener = new Button.onClickListener() {
0086 
0087         public void onClick(View v) {
0088             if (Utils.isMonkeyRunning()) {
0089                 return;
0090             }
0091 
0092             Intent intent = new Intent(getActivity(), Blank.class);
0093             intent.putExtras(getArguments());
0094 
0095             startActivity(intent);
0096         }
0097     };
0098 
0099     private void establishFinalConfirmationState() {
0100         mFinalButton = (Button) mContentView.findViewById(R.id.execute_encrypt);
0101         mFinalButton.setonClickListener(mFinalClickListener);
0102     }
0103 
0104     @Override
0105     public View onCreateView(LayoutInflater inflater, ViewGroup container,
0106             Bundle savedInstanceState) {
0107         mContentView = inflater.inflate(R.layout.crypt_keeper_/confirm/i, null);
0108         establishFinalConfirmationState();
0109         return mContentView;
0110     }
0111 }






<string name="crypt_keeper_desc" product="tablet" msgid="3839235202103924154">"您可以加密自己的帐户、设置、已下载的应用及其数据、媒体和其他文件。加密平板电脑后,您每次开机时都需要输入数字 PIN 或密码才能解密。取消加密的唯一方法就是恢复出厂设置,但这会清除平板电脑上的所有数据。" "加密过程需要 1 小时或更长时间。在开始加密前,电池必须有电,并且在加密完成前必须一直连接电源。如果您中断加密过程,则会丢失部分或全部数据。"</string>




<string name="crypt_keeper_button_text" product="default" msgid="2008346408473255519">"加密手机"</string>










五、encryptStorage的来源


http://osxr.org/android/source/frameworks/base/core/java/android/os/storage/IMountService.java#0628 




public int encryptStorage(String password) throws RemoteException {
0629                 Parcel _data = Parcel.obtain();
0630                 Parcel _reply = Parcel.obtain();
0631                 int _result;
0632                 try {
0633                     _data.writeInterfaceToken(DEscriptOR);
0634                     _data.writeString(password);
0635                     mRemote.transact(Stub.TRANSACTION_encryptStorage, _data, _reply, 0);
0636                     _reply.readException();
0637                     _result = _reply.readInt();
0638                 } finally {
0639                     _reply.recycle();
0640                     _data.recycle();
0641                 }
0642                 return _result;
0643             }
0644 

    以上就是本篇文章【设置-安全-手机加密功能讲解加密手机「设置-安全-手机加密功能讲解」】的全部内容了,欢迎阅览 ! 文章地址:http://www.uqian.cn/quote/9246.html 
     行业      资讯      企业新闻      行情      企业黄页      同类资讯      网站地图      返回首页 极顶速云移动站 http://m.uqian.cn/ , 查看更多