Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add a helper to adjust notifications permissions #139

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -168,6 +168,7 @@ export class SettingsApp {
setWifiState = setWifiState;

getNotifications = getNotifications;
adjustNotificationsPermissions = adjustNotificationsPermissions;
getSmsList = getSmsList;

performEditorAction = performEditorAction;
Expand Down
25 changes: 24 additions & 1 deletion lib/commands/notifications.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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<boolean>} 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;
}
3 changes: 1 addition & 2 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ 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`;

export const MEDIA_SCAN_RECEIVER = `${SETTINGS_HELPER_ID}/.receivers.MediaScannerReceiver`;
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`;
Loading