def test_GettersAndSetters(): categories = set([Intent.CATEGORY_DEFAULT, Intent.CATEGORY_LAUNCHER]) intent = Intent.Intent(Intent.ACTION_MAIN) intent.setPackage('com.example.app') map(intent.addCategory, categories) intent.setDataAndTypeAndNormalize( Uri.parse('content://com.example.app/users/1'), "text/x-vCard") intent.setComponent(ComponentName('package.name', 'class.name')) intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP) assert intent.getAction() == Intent.ACTION_MAIN assert intent.getPackage() == 'com.example.app' assert all(map(intent.hasCategory, categories)) assert intent.getCategories() == categories assert intent.getData() == Uri.parse('content://com.example.app/users/1') assert intent.getDataString() == 'content://com.example.app/users/1' assert intent.getType() == 'text/x-vcard' assert intent.getComponent().equals( ComponentName('package.name', 'class.name')) assert intent.getScheme() == 'content' flags = (Intent.FLAG_ACTIVITY_CLEAR_TASK, Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY, Intent.FLAG_ACTIVITY_SINGLE_TOP) iflags = intent.getFlags() assert all(map(lambda x: bool(x & iflags), flags))
class InstalledPackages(IBaseColumns): BASE_CONTENT_URI # Table name used by our database TABLE_NAME = "installed_packages" # Package name as it is stated in the AndroidManifest.xml file COLUMN_NAME = "name" # Path to the AndroidManifest.xml file COLUMN_PATH = "path" """ /* The base CONTENT_URI used to query the installed_packages table from the content provider */ """ CONTENT_URI = Uri.withAppendedPath(BASE_CONTENT_URI, TABLE_NAME) @staticmethod def buildUriWithId(id): """ * Builds a URI that adds the task _ID to the end of the todo content URI path. * This is used to query details about a single todo entry by _ID. This is what we * use for the detail view query. * :param id: Unique id pointing to that row :return: to query details about a single todo entry """ return Uri.withAppendedPath(BASE_CONTENT_URI, '%s/%s' % (SystemComponents.TABLE_NAME, str(id)))
class SystemComponents(IBaseColumns): BASE_CONTENT_URI # Table name used by our database TABLE_NAME = "system_components" # Identifier in the SystemsComponents table for the manifest tag of this package COLUMN_PACKAGE_ID = "package_id" # Date is stored as int representing time of creation of task COLUMN_PARENT = "parent" # Task is stored as String representing work to be done COLUMN_TYPE = "tag_type" # Status is stored as boolean representing current status of task COLUMN_CONTENT = "content" """ /* The base CONTENT_URI used to query the SystemComponents table from the content provider */ """ CONTENT_URI = Uri.withAppendedPath(BASE_CONTENT_URI, TABLE_NAME) @staticmethod def buildUriWithId(id): """ * Builds a URI that adds the task _ID to the end of the todo content URI path. * This is used to query details about a single todo entry by _ID. This is what we * use for the detail view query. * :param id: Unique id pointing to that row :return: to query details about a single todo entry """ return Uri.withAppendedPath(BASE_CONTENT_URI, '%s/%s' % (SystemComponents.TABLE_NAME, str(id)))
class TodoEntry(IBaseColumns): global BASE_CONTENT_URI # Table name used by our database TABLE_NAME = "todo" # Date is stored as int representing time of creation of task COLUMN_DATE = "date" # Task is stored as String representing work to be done COLUMN_TASK = "task" # Status is stored as boolean representing current status of task COLUMN_STATUS = "status" """ /* The base CONTENT_URI used to query the Todo table from the content provider */ """ CONTENT_URI = Uri.withAppendedPath(BASE_CONTENT_URI.toString(), TABLE_NAME) def buildTodoUriWithId(self, id): """ * Builds a URI that adds the task _ID to the end of the todo content URI path. * This is used to query details about a single todo entry by _ID. This is what we * use for the detail view query. * :param id: Unique id pointing to that row :return: to query details about a single todo entry """ return Uri.withAppendedPath(BASE_CONTENT_URI.toString(), '%s/%s' % (self.TABLE_NAME, str(id)))
def test_toUri(): packageName = 'com.example.app' data1 = Uri.parse('http://example.com') data2 = Uri.parse('http://example.com/foo?1234') intent = Intent.Intent(Intent.ACTION_MAIN).setPackage(packageName) assert intent.toUri( Intent.URI_ANDROID_APP_SCHEME) == 'android-app://com.example.app/' intent = Intent\ .Intent(Intent.ACTION_VIEW)\ .setPackage(packageName)\ .setData(data1) assert intent.toUri(Intent.URI_ANDROID_APP_SCHEME) == \ 'android-app://com.example.app/http/example.com' intent = Intent\ .Intent(Intent.ACTION_VIEW)\ .setPackage(packageName)\ .setData(data2) assert intent.toUri(Intent.URI_ANDROID_APP_SCHEME) == \ 'android-app://com.example.app/http/example.com/foo?1234' intent = Intent \ .Intent('com.example.MY_ACTION') \ .setPackage(packageName) assert intent.toUri(Intent.URI_ANDROID_APP_SCHEME) == \ 'android-app://com.example.app/#Intent;action=com.example.MY_ACTION;end' intent = Intent\ .Intent('com.example.MY_ACTION')\ .setPackage(packageName)\ .setData(data2) assert intent.toUri(Intent.URI_ANDROID_APP_SCHEME) == \ 'android-app://com.example.app/http/example.com/foo?1234#Intent;action=com.example.MY_ACTION;end' intent = Intent\ .Intent('com.example.MY_ACTION')\ .setPackage(packageName)\ .putExtra('some_int', 100)\ .putExtra('some_str', 'hello') assert intent.toUri(Intent.URI_ANDROID_APP_SCHEME) == \ 'android-app://com.example.app/#Intent;action=com.example.MY_ACTION;' \ 'i.some_int=100;S.some_str=hello;end'
def buildUriWithId(id): """ * Builds a URI that adds the task _ID to the end of the todo content URI path. * This is used to query details about a single todo entry by _ID. This is what we * use for the detail view query. * :param id: Unique id pointing to that row :return: to query details about a single todo entry """ return Uri.withAppendedPath(BASE_CONTENT_URI, '%s/%s' % (SystemComponents.TABLE_NAME, str(id)))
def test_ParcelAndUnparcel(): uri = 'android-app://com.example.app/#Intent;action=com.example.MY_ACTION;' \ 'i.some_int=100;S.some_str=hello;end' intent = Intent.Intent.parseUri(uri, Intent.URI_ANDROID_APP_SCHEME) intent.setData(Uri.parse('content://com.example.app/users/1')) p = Parcel() intent.writeToParcel(p, 0) p.setDataPosition(0) other = Intent.Intent.CREATOR.createFromParcel(p) assert intent.getAction() == other.getAction() assert intent.getData() == other.getData() assert intent.getType() == other.getType() assert intent.getFlags() == other.getFlags() assert intent.getComponent() == other.getComponent() assert intent.getSourceBounds() == other.getSourceBounds() assert intent.getCategories() == other.getCategories() assert intent.getClipData() == other.getClipData()
def test_selector(): uri = 'android-app://com.example.app/#Intent;action=com.example.MY_ACTION;' \ 'i.some_int=100;S.some_str=hello;end' intent = Intent.Intent.parseUri(uri, Intent.URI_ANDROID_APP_SCHEME) intent.setDataAndTypeAndNormalize( Uri.parse('content://com.example.app/users/1'), "text/x-vCard") clone = intent.clone() filter = intent.cloneFilter() assert intent.filterEquals(clone) assert intent.filterEquals(filter) assert clone.filterEquals(filter) other = Intent.Intent(Intent.ACTION_VIEW)\ .setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_CLEAR_TASK) assert filter.getFlags() == 0 filter.fillIn(other, 0) assert filter.getFlags() == other.getFlags() filter.fillIn(other, Intent.FILL_IN_ACTION) assert filter.getAction() == other.getAction()
def test_filterResolution(intentFilters): action = ACTION_MAIN matches = getMatchFilters(intentFilters, action) assert matches == [0], 'match: Not match' action = ACTION_MAIN category = CATEGORY_LAUNCHER matches = getMatchFilters(intentFilters, action, category=category) assert matches == [0], 'match: Not match' action = ACTION_VIEW data = Uri.parse('content://com.google.provider.NotePad/notes') categories = '' matches = getMatchFilters(intentFilters, action, data=data) assert matches == [1], 'match: Not match' action = ACTION_PICK data = Uri.parse('content://com.google.provider.NotePad/notes') matches = getMatchFilters(intentFilters, action, data=data) assert matches == [1], 'match: Not match' action = ACTION_GET_CONTENT mimetype = 'vnd.android.cursor.item/vnd.google.note' matches = getMatchFilters(intentFilters, action, mimetype=mimetype) assert matches == [2], 'match: Not match' action = ACTION_VIEW data = Uri.parse('content://com.google.provider.NotePad/notes/1234') matches = getMatchFilters(intentFilters, action, data=data) assert matches == [3], 'match: Not match' action = ACTION_EDIT data = Uri.parse('content://com.google.provider.NotePad/notes/1234') matches = getMatchFilters(intentFilters, action, data=data) assert matches == [3], 'match: Not match' action = ACTION_INSERT data = Uri.parse('content://com.google.provider.NotePad/notes') matches = getMatchFilters(intentFilters, action, data=data) assert matches == [4], 'match: Not match' action = 'com.android.notepad.action.EDIT_TITLE' data = Uri.parse('content://com.google.provider.NotePad/notes/1234') matches = getMatchFilters(intentFilters, action, data=data) assert matches == [5], 'match: Not match'
def test_parseUri(): flags = Intent.URI_ANDROID_APP_SCHEME uri = 'android-app://com.example.app/' intent = Intent.Intent.parseUri(uri, flags) assert intent.getAction() == Intent.ACTION_MAIN, \ "parseUri: Bad action resolution" assert intent.getPackage() == 'com.example.app', \ "parseUri: Bad package resolution" assert intent.getData() == None, \ "parseUri: Bad data resolution" assert intent.toUri(Intent.URI_ANDROID_APP_SCHEME) == uri uri = 'android-app://com.example.app/http/example.com' intent = Intent.Intent.parseUri(uri, flags) assert intent.getAction() == Intent.ACTION_VIEW, \ "parseUri: Bad action resolution" assert intent.getPackage() == 'com.example.app', \ "parseUri: Bad package resolution" assert intent.getData() == Uri.parse('http://example.com'), \ "parseUri: Bad data resolution" assert intent.toUri(Intent.URI_ANDROID_APP_SCHEME) == uri uri = 'android-app://com.example.app/http/example.com/foo?1234' intent = Intent.Intent.parseUri(uri, flags) assert intent.getAction() == Intent.ACTION_VIEW, \ "parseUri: Bad action resolution" assert intent.getPackage() == 'com.example.app', \ "parseUri: Bad package resolution" assert intent.getData() == Uri.parse('http://example.com/foo?1234'), \ "parseUri: Bad data resolution" assert intent.toUri(Intent.URI_ANDROID_APP_SCHEME) == uri uri = 'android-app://com.example.app/#Intent;action=com.example.MY_ACTION;end' intent = Intent.Intent.parseUri(uri, flags) assert intent.getAction() == 'com.example.MY_ACTION', \ "parseUri: Bad action resolution" assert intent.getPackage() == 'com.example.app', \ "parseUri: Bad package resolution" assert intent.getData() == None, \ "parseUri: Bad data resolution" assert intent.toUri(Intent.URI_ANDROID_APP_SCHEME) == uri uri = 'android-app://com.example.app/http/example.com/foo?1234#Intent;action=com.example.MY_ACTION;end' intent = Intent.Intent.parseUri(uri, flags) assert intent.getAction() == 'com.example.MY_ACTION', \ "parseUri: Bad action resolution" assert intent.getPackage() == 'com.example.app', \ "parseUri: Bad package resolution" assert intent.getData() == Uri.parse('http://example.com/foo?1234'), \ "parseUri: Bad data resolution" assert intent.toUri(Intent.URI_ANDROID_APP_SCHEME) == uri uri = 'android-app://com.example.app/#Intent;action=com.example.MY_ACTION;' \ 'i.some_int=100;S.some_str=hello;end' intent = Intent.Intent.parseUri(uri, flags) assert intent.getAction() == 'com.example.MY_ACTION', \ "parseUri: Bad action resolution" assert intent.getPackage() == 'com.example.app', \ "parseUri: Bad package resolution" assert intent.getData() == None, \ "parseUri: Bad data resolution" required = {'some_int': 100, 'some_str': 'hello'}.items() extras = intent.getExtras() assert all(map(lambda x: extras.get(x[0]) == x[1], required)), \ "parseUri: Bad extras resolution"
from Android.Uri import Uri """ The "Content authority" is a name for the entire content provider, similar to the relationship between a domain name and its website. A convenient string to use for the content authority is the package name for the app, which is guaranteed to be unique on the Play Store. """ CONTENT_AUTHORITY = "com.androidapps.systemmanager" """ Use CONTENT_AUTHORITY to create the base of all URI's which apps will use to contact the content provider for Sunshine. """ BASE_CONTENT_URI = Uri.parse("content://" + CONTENT_AUTHORITY) class SystemComponents(IBaseColumns): BASE_CONTENT_URI # Table name used by our database TABLE_NAME = "system_components" # Identifier in the SystemsComponents table for the manifest tag of this package COLUMN_PACKAGE_ID = "package_id" # Date is stored as int representing time of creation of task COLUMN_PARENT = "parent" # Task is stored as String representing work to be done COLUMN_TYPE = "tag_type" # Status is stored as boolean representing current status of task COLUMN_CONTENT = "content"