Android Development Android Security 1 — Questions and Answers
Question 1: What is the purpose of declaring permissions in AndroidManifest.xml?
- To declare what capabilities or data access the app requires (Correct answer)
- To hide the app from unauthorized users
- To encrypt app data
- To restrict other apps from running
Correct answer: To declare what capabilities or data access the app requires
Declaring permissions in the manifest tells the Android system and users what sensitive resources or data the app needs access to.
Question 2: Which protection level requires the user to explicitly grant a permission at runtime?
- dangerous (Correct answer)
- normal
- signature
- privileged
Correct answer: dangerous
Permissions with protection level 'dangerous' require explicit user approval at runtime because they access sensitive data or device features.
Question 3: Which Android API checks whether a runtime permission has been granted?
- ContextCompat.checkSelfPermission() (Correct answer)
- ActivityCompat.requestPermissions()
- PackageManager.hasPermission()
- Permission.isGranted()
Correct answer: ContextCompat.checkSelfPermission()
ContextCompat.checkSelfPermission() returns PERMISSION_GRANTED or PERMISSION_DENIED to indicate whether the app has a specific runtime permission.
Question 4: What does ProGuard/R8 do in Android release builds?
- Shrinks, obfuscates, and optimizes code (Correct answer)
- Encrypts APK resources
- Signs the APK
- Validates permissions
Correct answer: Shrinks, obfuscates, and optimizes code
ProGuard/R8 removes unused code, renames classes and methods to short names, and optimizes bytecode to reduce APK size and hinder reverse engineering.
Question 5: What is the Android Keystore System used for?
- To securely store cryptographic keys that cannot be extracted from the device (Correct answer)
- To manage user passwords
- To store API keys in plaintext
- To generate SSL certificates
Correct answer: To securely store cryptographic keys that cannot be extracted from the device
The Android Keystore System allows apps to generate and store cryptographic keys in a secure container, making them difficult to extract from the device.
Question 6: Which class is used to encrypt data using the Android Keystore in modern Android?
- Cipher (Correct answer)
- KeyGenerator
- EncryptionManager
- SecretKeyFactory
Correct answer: Cipher
The Cipher class from javax.crypto is initialized with keys from the Android Keystore to perform encryption and decryption operations.
What is the purpose of declaring permissions in AndroidManifest.xml?