@dderevjanik/termux-api
Version:
This library allows you to interact with your Android device from Node.js using termux-api
137 lines (117 loc) • 2.49 kB
text/typescript
import { exec } from "child_process";
/**
* Represents the telephony device information.
*/
export interface TelephonyDeviceInfo {
/**
* Indicates if data is enabled.
* @example "false"
*/
data_enabled: string;
/**
* The current data activity state.
* @example "dormant"
*/
data_activity: string;
/**
* The current data connection state.
* @example "disconnected"
*/
data_state: string;
/**
* The device ID.
* @example null
*/
device_id: string | null;
/**
* The software version of the device.
* @example "75"
*/
device_software_version: string;
/**
* The number of phones.
* @example 2
*/
phone_count: number;
/**
* The type of phone.
* @example "gsm"
*/
phone_type: string;
/**
* The network operator code.
* @example "23103"
*/
network_operator: string;
/**
* The name of the network operator.
* @example "4KA SK"
*/
network_operator_name: string;
/**
* The ISO country code of the network.
* @example "sk"
*/
network_country_iso: string;
/**
* The type of network.
* @example "lte"
*/
network_type: string;
/**
* Indicates if the network is roaming.
* @example false
*/
network_roaming: boolean;
/**
* The ISO country code of the SIM.
* @example "sk"
*/
sim_country_iso: string;
/**
* The SIM operator code.
* @example "23103"
*/
sim_operator: string;
/**
* The name of the SIM operator.
* @example "4KA SK"
*/
sim_operator_name: string;
/**
* The serial number of the SIM.
* @example null
*/
sim_serial_number: string | null;
/**
* The subscriber ID of the SIM.
* @example null
*/
sim_subscriber_id: string | null;
/**
* The state of the SIM.
* @example "ready"
*/
sim_state: string;
}
/**
* Call a telephony number
*
* **Requires permission** `android.permission.READ_PHONE_STATE`
*/
export async function telephonyDeviceInfo(): Promise<TelephonyDeviceInfo> {
return new Promise<TelephonyDeviceInfo>((resolve, reject) => {
const command = `termux-telephony-deviceinfo`;
exec(command, (error, stdout, stderr) => {
if (error) {
return reject(`Error: ${error.message}`);
}
if (stderr) {
return reject(`Error: ${stderr}`);
}
const output = stdout.trim();
const deviceInfo: TelephonyDeviceInfo = JSON.parse(output);
return resolve(deviceInfo);
});
});
}