Share
Embed
Annual Pro sale · Save $30
Have presentations of your own?
Share with private links, password protection, and more control over your work.
Transcript
75 slides
-
SystemΞϓϦ։ൃೖ ! @kobashinG 4 ࠓ͓͢Δ͜ͱ 1. SystemΞϓϦͱύʔϛογϣϯ 2. SystemΞϓϦͱϚϧνϢʔβʔ 3.
SystemΞϓϦͱ։ൃڥ ͓·͚ʹ͍ۙ -
SystemΞϓϦ։ൃೖ ! @kobashinG 5 λʔήοτ • SystemΞϓϦΛ։ൃͨ͜͠ͱ͕ແ͍ • platformॺ໊ͷཁෆཁʹ໎ͬͨ͜ͱ͕͋Δ ͱΓ͋͑ͣॺ໊͚ͭͱ͚
• SystemΞϓϦͰϚϧνϢʔβʔαϙʔτ Λ͍ͨ͠ -
SystemΞϓϦ։ൃೖ ! @kobashinG 6 ҙࣄ߲ • ຊ͓͢Δ͜ͱɺandroid-7.1.1_r13 Λϕʔεʹ͍ͯ͠·͢ • ಈ࡞֬ೝʹNexus6Λར༻
Tablet-UI, Restricted profileͷ֬ೝ༻ʹ গ͠ROMΛ࿔ͬͯ·͢ -
SystemΞϓϦ։ൃೖ ! @kobashinG 9 AndroidʹΠϯετʔϧ͞Ε͍ͯΔΞϓϦ # # # # GooglePlay
͔Β SystemΞϓϦʹʹϓϦΠϯ -
SystemΞϓϦ։ൃೖ ! @kobashinG 10 AndroidʹΠϯετʔϧ͞Ε͍ͯΔΞϓϦ • System.imgʹؚ·Εͳ͍௨ৗͷΞϓϦ • System.imgʹؚ·ΕΔΞϓϦ •
PrivilegedΞϓϦ • sharedUserId=“android.uid.xxxx” • ಛఆͷॺ໊͖ΞϓϦ • etc… SystemΞϓϦ -
SystemΞϓϦ։ൃೖ ! @kobashinG 11 ௨ৗͷΞϓϦͱSystemΞϓϦͱͷҧ͍ • ύʔϛογϣϯϞσϧʹΑΓ੍ݶ͞Εͨ APIͷར༻ • @hide
API, @systemApiͷར༻ • ಉuid͔ΒͷΈͷΞΫηεՄAPIͷར༻ $ Πϯετʔϧख๏ʹΑΓݖݶ͕ҟͳΔ ∠ -
SystemΞϓϦ։ൃೖ ! @kobashinG 13 ύʔϛογϣϯϞσϧ • ΞϓϦ͕อ࣋͢ΔύʔϛογϣϯͷΈ ΞϓϦαϯυϘοΫε֎ͷϦιʔεͷ ΞΫηεڐՄΛ༩͑Δ MyApp
INTERNET # % & device API INTERNET CAMERA CAMERA -
SystemΞϓϦ։ൃೖ ! @kobashinG 14 protectionLevel = BasicProtection | AdditionalFlag ex.
signatureOrSystem = signature | privileged ϓϩςΫγϣϯϨϕϧ + permission: a.p.WRITE_MEDIA_STORAGE package: android label: null description: null protectionLevel: signature|privileged -
SystemΞϓϦ։ൃೖ ! @kobashinG 15 Basic Protection Type ֓ཁɺڐՄ݅ normal ϦεΫ
dangerous Ϣʔβͷݸਓใอଘσʔλ ͷΞΫηε͕ൃੜ͢Δ signature ύʔϛογϣϯͷఆٛऀͱಉ͡ॺ ໊Λ࣋ͭΞϓϦ signatureOrSystem signatureݖݶɺSystemΞϓϦ -
SystemΞϓϦ։ൃೖ ! @kobashinG 16 Additional Flag ֓ཁɺڐՄ݅ privileged(system) /system/priv-app ҎԼʹΠϯετʔϧ
͞ΕͨΞϓϦ development ༧ΊڐՄ͍ͯ͠ͳ͍ͱڐՄͰ͖ͳ͍ installer Intent.ACTION_INSTALL_PACKAGEʹ Ԡ͢ΔActivityΛ࣋ͭΞϓϦ appop AppOpsͰཧ͞Ε͍ͯΔύʔϛογ ϣϯ -
SystemΞϓϦ։ൃೖ ! @kobashinG 17 Additional Flag ֓ཁɺڐՄ݅ pre23 targetSdkVersion <
23 verifier Intent.ACTION_PACKAGE_NEEDS_VER IFICATIONʹԠͰ͖ΔActivityΛ࣋ͭ setup Intent.CATEGORY_SETUP_WIZARDʹ ԠͰ͖ΔActivityΛ࣋ͭ preinstalled γεςϜΠϝʔδʹؚ·ΕΔશͯͷΞ ϓϦ -
SystemΞϓϦ։ൃೖ ! @kobashinG 19 APIΛ୳͢ • ྨࣅΞϓϦ͔ΒAPIΛ୳͢ • SettingsΞϓϦ͕࣋ͬͯΔ •
֘Օॴͷιʔε͔ΒAPIΛݟ͚ͭΔ private void doMasterClear() { Intent intent = new Intent(Intent.ACTION_MASTER_CLEAR); intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); intent.putExtra(Intent.EXTRA_REASON, "MasterClearConfirm"); intent.putExtra(Intent.EXTRA_WIPE_EXTERNAL_STORAGE, mEraseSdCard); getActivity().sendBroadcast(intent); // Intent handling is asynchronous -- assume it will happen soon. } MasterClearConfirm.java -
SystemΞϓϦ։ൃೖ ! @kobashinG 20 APIຖͷύʔϛογϣϯΛ֬ೝ <receiver android:name="com.android.server.MasterClearReceiver" android:permission="android.permission.MASTER_CLEAR"> <intent-filter android:priority="100"
> <!-- For Checkin, Settings, etc.: action=MASTER_CLEAR --> <action android:name="android.intent.action.MASTER_CLEAR" /> AndroidManifest.xml ΛFactoryReset͢ΔAPI ʮMASTER_CLEARʯ͕ඞཁ -
SystemΞϓϦ։ൃೖ ! @kobashinG 21 permissionͷprotectionLevelΛ֬ೝ $ adb shell pm list
permissions -f + permission:android.permission.MASTER_CLEAR package:android label:null description:null protectionLevel:signature|privileged ʮMASTER_CLEARʯ-> signature | privileged ॺ໊ or /system/priv-app Πϯετʔϧඞཁ -
SystemΞϓϦ։ൃೖ ! @kobashinG 23 APIΛ୳͢ • XXManager͔ΒAPIΛ୳͢ • ֘Օॴͷιʔε͔ΒAPIΛݟ͚ͭΔ /**
* Forces the device to go to sleep. * * Requires the {@link android.Manifest.permission#DEVICE_POWER} * permission. * * @hide Requires signature permission. */ public void goToSleep(long time, int reason, int flags) { PowerManager.java -
SystemΞϓϦ։ൃೖ ! @kobashinG 24 APIຖͷύʔϛογϣϯΛ֬ೝ /** * Forces the device
to go to sleep. * * Requires the {@link android.Manifest.permission#DEVICE_POWER} * permission. * * @hide Requires signature permission. */ public void goToSleep(long time, int reason, int flags) { PowerManager.java ΛSleepঢ়ଶҠߦ͢ΔAPI ʮDEVICE_POWERʯ͕ඞཁ -
SystemΞϓϦ։ൃೖ ! @kobashinG 25 permissionͷprotectionLevelΛ֬ೝ $ adb shell pm list
permissions -f + permission:android.permission.DEVICE_POWER package:android label:null description:null protectionLevel:signature ʮDEVICE_POWERʯ-> signature͕ඞཁ platformॺ໊͕ඞཁ -
SystemΞϓϦ։ൃೖ ! @kobashinG 26 SystemΞϓϦͱύʔϛογϣϯ • ඞཁͳػೳʹ߹Θͤύʔϛογϣϯͷ protectionLevelΛ֬ೝ㱺ඞཁͳݖݶΛ༩ • AdditionalFlagͷৄࡉɺԼهॲཧ෦͕
Θ͔Γ͍͢ • PackageManagerService.grantSignaturePermission() -
SystemΞϓϦ։ൃೖ ! @kobashinG 28 sharedUserId=“android.uid.system” • uidΛݻఆԽʢuid = 1000ʣ •
uid.system͕࣋ͭϦιʔεͷΞΫηε • Ұ෦੍ݶAPIΛར༻Մೳʹ • platformॺ໊ඞཁ • ҰํɺWebView͕ར༻ෆՄೳʹ -
SystemΞϓϦ։ൃೖ ! @kobashinG 29 uidʹΑ੍ͬͯݶ͞ΕΔAPI /** * Validate a user-supplied
password string with cryptfs */ @Override public int verifyEncryptionPassword(String password) throws RemoteException { // Only the system process is permitted to validate passwords if (Binder.getCallingUid() != android.os.Process.SYSTEM_UID) { throw new SecurityException("no permission to access the crypt keeper"); } MountService.java ҉߸ԽFSͷύεϫʔυνΣοΫAPI -
SystemΞϓϦ։ൃೖ ! @kobashinG 30 uidʹΑ੍ͬͯݶ͞ΕΔAPI final int uid = android.os.Process.myUid();
if (uid == android.os.Process.ROOT_UID || uid == android.os.Process.SYSTEM_UID) { throw new UnsupportedOperationException( "For security reasons, WebView is not allowed in privileged processes"); } WebViewFactory.java ٯʹandroid.uid.systemͱ͢Δ͜ͱͰWebview ར༻Ͱ͖ͳ͘ͳΔ -
SystemΞϓϦ։ൃೖ ! @kobashinG 32 privileged? APIݕ౼ ҰൠAPP signature? uid? priv-app
signature sharedUid SystemΞϓϦͱύʔϛογϣϯ YES NO NO YES YES NO -
SystemΞϓϦ։ൃೖ ! @kobashinG 33 SystemΞϓϦͱύʔϛογϣϯ • APIྨࣅΞϓϦ or XXManager͔Β୳͢ •
Platformॺ໊͕ඞཁ͔Ͳ͏͔ • ԿͰ͚ͭΕྑ͍ͬͯͷͰແ͍ • uid.system੍ݶ͋Δ͜ͱʹҙ Point -
SystemΞϓϦ։ൃೖ ! @kobashinG 34 SystemΞϓϦͱύʔϛογϣϯ • Platformॺ໊Ҏ֎ʹUICCอଘॺ໊ͱ Ұக͠ͳ͚Εར༻ෆՄAPIଘࡏ͢Δ TelephonyManager.*ͱ͔ •
ΞοϓσʔτͷΞϯΠϯετʔϧ͕Մೳ • /system/appͷΞϓϦμϯάϨʔυ • migrationରԠΘ͢Εͣʹ -
SystemΞϓϦ։ൃೖ ! @kobashinG 35 SystemΞϓϦͱΞοϓσʔτ • ΞοϓσʔτࡁΈͷSystemΞϓϦ͔Ͳ͏͔ ্هAPIͰ֬ೝՄೳ /** *
@hide */ public boolean isUpdatedSystemApp() { return (flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0; } ApplicationInfo.java -
SystemΞϓϦ։ൃೖ ! @kobashinG 37 ϚϧνϢʔβʔ͓͞Β͍ Tablet • from 4.2 •
Restricted Profile Hand Set ※ݫີʹVoice capableʹର Ԡ͍ͯ͠Δ͔Ͳ͏͔ • from 5.0 -
SystemΞϓϦ։ൃೖ ! @kobashinG 38 ΞϓϦͷΠϯετʔϧͷ͞Εํ /data/user/ 0 10 11 •
Owner User • /data/data/ ͷSymbolic Link • New User • New Profile $ ΞϓϦέʔγϣϯσʔλϢʔβʔຖʹಠཱ -
SystemΞϓϦ։ൃೖ ! @kobashinG 39 ϢʔβʔؒͰσʔλڞ༗͍ͨ͠ • ΞϓϦσʔλ/EXTERNAL STORAGE σʔλڞʹϢʔβʔຖʹഉଞ •
ઃఆҾ͖ܧ͗ • ϢʔβʔຖʹৼΔ͍Λมߋ͍ͨ͠ service, receiverΛʮSingleton Componentʯʹ ∠ -
SystemΞϓϦ։ൃೖ ! @kobashinG 41 MyApp uid=0 MyApp uid=10 Activity Service
singleUser Activity Singleton Component service, receiversingleUse=“true”Λઃఆ uid=0 ͷcomponentΛSingletonͱͯ͠ར༻ -
SystemΞϓϦ։ൃೖ ! @kobashinG 42 ϚϧνϢʔβʔૢ࡞ʹඞཁͳॺ໊ • INTERACT_ACROSS_USER • signature |
privilege • Ϣʔβʔૢ࡞Ұൠʹඞཁ • INTERACT_ACROSS_USER_FULL • signature • ଞϢʔβʔͷActivityىಈ ଞϢʔβʔͷContentObserverొͳͲ -
SystemΞϓϦ։ൃೖ ! @kobashinG 43 Singleton Component <service android:name=".MultiUserSingletonService" android:enabled="true" android:exported="true"
android:singleUser="true" /> <receiver android:name=".MyReceiver" android:enabled="true" android:exported="true" android:singleUser="true"> AndroidManifest.xml -
SystemΞϓϦ։ൃೖ ! @kobashinG 44 Singleton Component @Override public int sampleAidlApi()
throws RemoteException { File file = getFilesDir(); // ͲͷϢʔβ͔ΒͰ /data/user/0/xxx.xxx.xxx/files Log.i(TAG, "filesDir: " + file.getAbsolutePath()); SampleService.java -
SystemΞϓϦ։ൃೖ ! @kobashinG 45 Singleton ComponentͰϢʔβʔνΣοΫ • UserHandle.getCallingUserId() • Binderܦ༝ͷAPIΞΫηεݩUIDΛऔಘ
• UserManager.getUserInfo() • ֤ϢʔβʔͷৄࡉใΛऔಘ -
SystemΞϓϦ։ൃೖ ! @kobashinG 46 Singleton Component @Override public int sampleAidlApi()
throws RemoteException { if( UserHandle.USER_SYSTEM == getCallingUserId()){ // USER_SYSTEM (uid == 0) } else { // other user (uid != 0) UserManager userManager = (UserManager) getSystemService(USER_SERVICE); UserInfo userInfo = ɹuserManager.getUserInfo(getCallingUserId()); // ֤ϢʔβຖͷInfo UserInfo{10:New user:10} Log.i(TAG, "UserInfo " + userInfo.toString()); } SampleService.java -
SystemΞϓϦ։ൃೖ ! @kobashinG 47 ϢʔβʔຖͷComponentΛىಈ͢Δ • startActivityAsUser(Intent, UserHandle) • UserΛࢦఆ͠ActivityΛىಈ
• ֤ίϯϙʔωϯτ༻ʹAsUser API͕ଘࡏ • ޡͬͨActivityΛىಈ͠Α͏ͱͨ͠߹ SecurityException͕ൃੜ͢Δ -
SystemΞϓϦ։ൃೖ ! @kobashinG 48 Singleton Component @Override public int sampleAidlApi()
throws RemoteException { // loginதϢʔβʔͷActivityىಈ Intent intent = new Intent(); intent.setClass(MultiUserSingletonService.this, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivityAsUser(intent, UserHandle.CURRENT); // uid=0ϢʔβʔͷServiceىಈ(SYSTEM=OWNER) startServiceAsUser(intent, UserHandle.SYSTEM); SampleService.java -
SystemΞϓϦ։ൃೖ ! @kobashinG 50 Restricted Profile • ੍ݶϢʔβʔʹɺΞϓ ϦέʔγϣϯͷڐՄঢ় ଶΛઃఆͰ͖Δ
• Intent.ACTION_GET_RES TRICTION_ENTRIESʹΑ Γ੍ݶ༰Λݸผʹઃ ఆͰ͖Δ -
SystemΞϓϦ։ൃೖ ! @kobashinG 51 SystemΞϓϦͱRestricted Profile • SystemΞϓϦͷදࣔ݅ • ॺ໊༗Γඇදࣔ
• platformॺ໊ແ͠දࣔ • platformॺ໊༗Γʴɹ Intent.ACTION_GET_REST RICTION_ENTRIESΛड৴ ͢ΔReceiver࣮ -
SystemΞϓϦ։ൃೖ ! @kobashinG 52 ະॺ໊ platformॺ໊ platformॺ໊ has receiver දࣔঢ়ଶ
දࣔ ඇදࣔ දࣔ + ' SystemΞϓϦͱRestricted Profile • platformॺ໊࣋ͪͷ߹ON/OFFઃఆͰ͖ͳ͍ ৄࡉઃఆΛߦ͏ͨΊʹ Intent.ACTION_GET_RESTRICTION_ENTRIESΛϋϯυϧ͢Δ -
SystemΞϓϦ։ൃೖ ! @kobashinG 54 SystemΞϓϦͱϚϧνϢʔβʔ • جຊҰൠΞϓϦͱมΘΒͳ͍ • ϢʔβʔؒͰσʔλڞ༗ɺϢʔβʔຖͷڍಈมߋ ɹ㱺singleUserͷservice,
receiverΛར༻͢Δ • Restricted Profileॺ໊༗ແͰڍಈมߋ͋Γ ඞཁʹԠ͡ACTION_GET_RESTRICTION_ENTRIESͷ ࣮ݕ౼Λʢ࣮༰ҰൠΞϓϦͱಉʣ -
SystemΞϓϦ։ൃೖ ! @kobashinG 57 AndroidSDKͷ࣋ͨͳ͍APIΛར༻͢Δ • AndroidSDKͷ࣋ͨͳ͍APIΛར༻ ɹ㱺௨ৗͷڥͩͱࢀরΤϥʔൃੜ • AOSPϏϧυڥͰϏϧυඞཁ
㱺IDE͕ར༻Ͱ͖ͳ͍ ʢEclipse༻ͷαϙʔτϖʔδ͕͋ͬͨɺ ɹAndroid Studio༻ແ͍ΑͶʁʣ -
SystemΞϓϦ։ൃೖ ! @kobashinG 58 AndroidSDKͷ࣋ͨͳ͍APIΛར༻͢Δ 1. AOSPͷϏϧυʢframework.jarੜʣ 2. framework.jarΛϥΠϒϥϦͱͯ͠ొ 3.
ϏϧυΤϥʔճආͷͨΊbuild.gradleมߋ 4. ॺ໊͕ඞཁͰ͋Ε༩͢Δ -
SystemΞϓϦ։ൃೖ ! @kobashinG 60 2. framework.jarΛϥΠϒϥϦͱͯ͠ొ 2. apkʹؚΊͳ͍Α͏ʹprovidedͰಡΈࠐΉ dependencies {
// build pathʹframework.jarΛؚΊΔɻAPKʹؚΊͳ͍ provided fileTree(dir: 'framework', include: ['*.jar']) } -
SystemΞϓϦ։ൃೖ ! @kobashinG 61 3. ϏϧυΤϥʔճආͷͨΊbuild.gradleมߋ • Editorapp.imlͷϥΠϒϥϦΛ্͔Βϩʔυ ͠ࢀরΛղܾ͢Δ •
framework.jarΛSDKΑΓ্ʹมߋ • build.gradleʹtaskॻ͍͓ͯ͘ͱศར -
SystemΞϓϦ։ൃೖ ! @kobashinG 62 import groovy.xml.* task changeOrderEntry { def
iml = file("app.iml") def doc = (new XmlParser()).parse(iml); def deleteNode = doc.component[1].orderEntry.find { it.@type == "jdk" } def _type = deleteNode.@type def _jdkName = deleteNode.@jdkName def _jdkType = deleteNode.@jdkType doc.component[1].remove(deleteNode) new Node(doc.component[1], 'orderEntry', ['type': _type, 'jdkName': _jdkName, 'jdkType': _jdkType]) iml.text = XmlUtil.serialize(doc) } preBuild.dependsOn(changeOrderEntry) 3. ϏϧυΤϥʔճආͷͨΊbuild.gradleมߋ -
SystemΞϓϦ։ൃೖ ! @kobashinG 63 tasks.withType(JavaCompile) { options.compilerArgs.add('-Xbootclasspath/p:app/framework/ framework.jar') } 3.
ϏϧυΤϥʔճආͷͨΊbuild.gradleมߋ • packageੜ࣌ʹBuildPathʹׂΓࠐΉʹ -Xbootclasspath/p: Λར༻͢Δ -
SystemΞϓϦ։ൃೖ ! @kobashinG 64 4. ॺ໊͕ඞཁͳΒ༩͢Δ • debugॺ໊ build/target/product/security •
keytool-importkeypair • https://github.com/getfatday/keytool-importkeypair signingConfigs { debug { storeFile file(“/path/to/debug.keystore") storePassword "android" keyAlias "platform" keyPassword "android" } } -
SystemΞϓϦ։ൃೖ ! @kobashinG 65 AndroidSDKͷ࣋ͨͳ͍APIΛར༻͢Δ • priv-appͷΠϯετʔϧผ్ඞཁ • ࠷ۙͷfirmdm-verity͕̤̣ͳͷͰ `adb
disable-verity; adb reboot;` ΛΕͣʹ • SDKͷjarΛฤू͢Δํ๏ͩͱɺ :app:mockableAndroidJar TaskͰΤϥʔൃੜ -
SystemΞϓϦ։ൃೖ ! @kobashinG 67 Debugging AOSP Source 1. user-debugͷ࣮ػΛ༻ҙ 2.
AOSPͷϏϧυ 3. ./development/tools/idegen/intellij-gen.sh ͰϓϩδΣΫτͷiprΛ࡞ 4. DDMSىಈ 5. studioͰಡΈࠐΈ & debug࣮ߦ -
SystemΞϓϦ։ൃೖ ! @kobashinG 68 $ ./development/tools/idegen/intellij-gen.sh \ packages/apps/Settings $
monitor iprͷ࡞ͱDDMSͷىಈ • intellij-gen.shΛར༻͠iprΛ࡞ • idegen.shͰߏΘͳ͍͕AOSPશମϝϞϦෛՙ • DDMS͕port:8700ͰσόΠεͱ௨৴ ಉportͰAndroid StudioͰremoteଓ͢Δ -
SystemΞϓϦ։ൃೖ ! @kobashinG 72 Debugging AOSP Source • Step࣮ߦࣗ༝ʹͰ͖ΔͷͰɺAOSPͷ ιʔεΛಡΉͱ͖ͷखॿ͚ʹ
• DDMSͷىಈॱʹΑͬͯ8700Ͱଓ Ͱ͖ͳ͍ͱ͖͋ΔͷͰҙ -
SystemΞϓϦ։ൃೖ ! @kobashinG 74 ·ͱΊ • ϏϧυίϚϯυϥΠϯͰӡ༻ਏ͍ • AOSPͷιʔεΛಡΉڥͱͯ͠1ͭ༻ҙ ͓ͯ͘͠ͱίʔυϦʔσΟϯάḿΔ
ʢIntellijͷBookmarkػೳͱ͔ศར͡Όͳ͍Ͱ͔͢ʣ