diff --git a/lib/client.js b/lib/client.js index 58da0b81..1f1635d1 100644 --- a/lib/client.js +++ b/lib/client.js @@ -8,7 +8,7 @@ import { setGeoLocation, getGeoLocation, refreshGeoLocationCache } from './comma import { setDeviceSysLocale } from './commands/locale'; import { scanMedia } from './commands/media'; import { setDataState, setWifiState } from './commands/network'; -import { getNotifications } from './commands/notifications'; +import { getNotifications, adjustNotificationsPermissions } from './commands/notifications'; import { getSmsList } from './commands/sms'; import { performEditorAction, typeUnicode } from './commands/typing'; @@ -168,6 +168,7 @@ export class SettingsApp { setWifiState = setWifiState; getNotifications = getNotifications; + adjustNotificationsPermissions = adjustNotificationsPermissions; getSmsList = getSmsList; performEditorAction = performEditorAction; diff --git a/lib/commands/notifications.js b/lib/commands/notifications.js index 14da363b..975b0aac 100644 --- a/lib/commands/notifications.js +++ b/lib/commands/notifications.js @@ -1,5 +1,8 @@ import { LOG_PREFIX } from '../logger'; -import { NOTIFICATIONS_RETRIEVAL_ACTION } from '../constants'; +import { + NOTIFICATIONS_RETRIEVAL_ACTION, + SETTING_NOTIFICATIONS_LISTENER_SERVICE, +} from '../constants'; /** * Retrieves Android notifications via Appium Settings helper. @@ -69,3 +72,23 @@ export async function getNotifications () { } return this._parseJsonData(output, 'notifications'); }; + +/** + * Adjusts the necessary permissions for the + * Notifications retreval service for Android API level 29+ + * + * @this {import('../client').SettingsApp} + * @returns {Promise} If permissions adjustment has been actually made + */ +export async function adjustNotificationsPermissions() { + if (await this.adb.getApiLevel() >= 29) { + await this.adb.shell([ + 'cmd', + 'notification', + 'allow_listener', + SETTING_NOTIFICATIONS_LISTENER_SERVICE, + ]); + return true; + } + return false; +} diff --git a/lib/constants.js b/lib/constants.js index 31b5bf0b..dc0853c8 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -23,8 +23,6 @@ export const LOCATION_SERVICE = `${SETTINGS_HELPER_ID}/.LocationService`; export const LOCATION_RECEIVER = `${SETTINGS_HELPER_ID}/.receivers.LocationInfoReceiver`; export const LOCATION_RETRIEVAL_ACTION = `${SETTINGS_HELPER_ID}.location`; -export const NOTIFICATIONS_RETRIEVAL_ACTION = `${SETTINGS_HELPER_ID}.notifications`; - export const SMS_LIST_RECEIVER = `${SETTINGS_HELPER_ID}/.receivers.SmsReader`; export const SMS_LIST_RETRIEVAL_ACTION = `${SETTINGS_HELPER_ID}.sms.read`; @@ -32,3 +30,4 @@ export const MEDIA_SCAN_RECEIVER = `${SETTINGS_HELPER_ID}/.receivers.MediaScanne export const MEDIA_SCAN_ACTION = `${SETTINGS_HELPER_ID}.scan_media`; export const SETTING_NOTIFICATIONS_LISTENER_SERVICE = `${SETTINGS_HELPER_ID}/.NLService`; +export const NOTIFICATIONS_RETRIEVAL_ACTION = `${SETTINGS_HELPER_ID}.notifications`;