To answer your second question:
Assuming your package name is com.companyname
Create an Authenticator class that extends AbstractAccountAuthenticator in the package com.companyname.auth and implement this method on it:
@Override
public Bundle getAccountRemovalAllowed(AccountAuthenticatorResponse response, Account account) {
Bundle result = new Bundle();
boolean allowed = false; // or whatever logic you want here
result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, allowed);
return result;
}
Add this to the manifest:
<service android:name=".auth.AuthenticationService">
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator"></action>
</intent-filter>
<meta-data android:name="android.accounts.AccountAuthenticator" android:resource="@xml/authenticator"></meta-data>
</service>
(Note that lint gives a warning that this exported service does not require permissions).
And then in res/xml add the authenticator.xml file:
<?xml version="1.0" encoding="utf-8"?>
<account-authenticator
xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="com.companyname"
android:icon="@drawable/app_icon"
android:smallIcon="@drawable/app_icon_small"
android:label="@string/app_name" />
Assuming that your account type is "com.companyname". That's what we do and it appears to be working from API 8 on up.