Skip to content

Instantly share code, notes, and snippets.

@jzallas
Created July 20, 2024 20:21
Show Gist options
  • Save jzallas/05a6be57f99768e28cfeebacddba54d3 to your computer and use it in GitHub Desktop.
Save jzallas/05a6be57f99768e28cfeebacddba54d3 to your computer and use it in GitHub Desktop.
Debloat z-fold6
const data = require('./definitions.json');
const definitions = data.reduce((acc, item) => {
const { id, ...others } = item
acc[item.id] = others
return acc
}, {})
const { exec } = require('child_process');
const util = require('util');
const execPromise = util.promisify(exec);
const readline = require('readline')
const fs = require('fs');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
async function execute(command) {
try {
const { stdout, stderr } = await execPromise(command);
if (stderr) {
throw new Error(stderr);
}
return stdout;
} catch (error) {
throw new Error(`Error executing command: ${error.message}`);
}
}
const askQuestion = (query) => {
return new Promise((resolve) => {
rl.question(query, (answer) => {
resolve(answer);
});
});
};
function writeScript(uninstall, disable) {
console.log(`Marking ${uninstall.length} packages to delete.`)
console.log(`Marking ${disable.length} packages to disable.`)
const script =
`
#!/bin/bash
# disables bloat packages on samsung devices
packages_to_uninstall=(
${uninstall.map(p => `"${p.id}"`).join(' \\ \n ')}
)
packages_to_disable=(
${disable.map(p => `"${p.id}"`).join(' \\\n ')}
)
for package in "\${packages_to_uninstall[@]}"
do
echo "Uninstalling $package..."
adb shell pm uninstall -k --user 0 $package
done
for package in "\${packages_to_disable[@]}"
do
echo "Disabling $package..."
adb shell pm disable-user --user 0 $package
done
`
const filePath = "debloat.sh"
fs.writeFile(filePath, script, "utf-8", (err) => {
if (err) {
console.error('An error occurred while writing the array to the file:', err);
} else {
console.log(`Array successfully written to ${filePath}`);
}
})
}
async function scriptForRecommendations(recommended) {
let uninstall = []
let disable = []
for (let i = 0; i < recommended.length; i++) {
const p = recommended[i];
console.log(`=== Package ${i+1} of ${recommended.length} ===`)
console.log(p);
const input = await askQuestion('(1) kill, (2) sleep, (3) idk: ');
if (input == "1") {
uninstall.push(p);
} else if (input == "2") {
disable.push(p);
} else if (input == "0") {
break;
}
}
rl.close()
writeScript(uninstall, disable)
}
(async () => {
const result =
(await execute("adb shell pm list packages -a -e --user 0"))
.split('\n')
.filter(line => line) // Remove empty lines
.map(line => line.replace('package:', ''))
.map(pkg => {
return {
id: pkg,
isKnown: !(definitions[pkg] === undefined),
...definitions[pkg]
}
})
const known = result.filter(p => p.isKnown)
console.log(`Currently ${known.length} known packages.`)
const unknown = result.filter(p => !p.isKnown)
console.log(`Currently ${unknown.length} unknown packages.`)
const recommended = known.filter(p => p.removal == "Recommended")
console.log(`Currently ${recommended.length} recommended for removal.`)
await scriptForRecommendations(recommended)
})()
#!/bin/bash
# disables bloat packages on samsung devices
packages_to_uninstall=(
"com.samsung.android.app.tips" \
"com.android.dreams.phototable" \
"com.samsung.android.app.spage" \
"com.facebook.appmanager" \
"com.samsung.android.app.watchmanager" \
"com.microsoft.office.outlook" \
"com.samsung.android.mdx" \
"com.hiya.star" \
"com.spotify.music" \
"com.samsung.android.shortcutbackupservice" \
"com.microsoft.office.officehubrow" \
"com.samsung.android.app.watchmanagerstub" \
"com.sec.android.easyMover.Agent" \
"com.google.android.apps.youtube.music" \
"com.sec.android.easyMover" \
"com.facebook.system" \
"com.linkedin.android" \
"com.samsung.vvm" \
"com.microsoft.skydrive" \
"com.netflix.mediaclient" \
"com.google.android.videos" \
"com.facebook.services" \
"com.samsung.android.smartswitchassistant" \
"com.microsoft.appmanager" \
"com.sec.android.app.chromecustomizations" \
"com.samsung.android.voc" \
"com.android.providers.partnerbookmarks" \
"com.samsung.android.kidsinstaller" \
"com.facebook.katana" \
"com.touchtype.swiftkey" \
"com.swiftkey.swiftkeyconfigurator" \
)
packages_to_disable=(
"com.samsung.android.messaging" \
"com.sec.android.easyMover" \
"com.samsung.android.oneconnec" \
"com.samsung.android.oneconnect" \
"com.samsung.android.tvplus" \
"com.sec.android.app.shealth" \
"com.samsung.android.voc" \
"com.samsung.android.app.watchmanager" \
"com.samsung.sree" \
"com.samsung.android.app.spage" \
"com.samsung.android.app.tips" \
"com.samsung.android.contacts" \
"com.samsung.android.app.contacts" \
"com.samsung.android.calendar" \
"com.samsung.android.dialer" \
"com.samsung.android.spay" \
"com.vzw.apnlib"
"com.samsung.android.aremojieditor" \
"com.samsung.android.ardrawing" \
"com.samsung.android.app.camera.sticker.facearavatar.preload" \
"com.sec.android.mimage.avatarstickers" \
"com.samsung.android.app.settings.bixby" \
"com.samsung.android.samsungpass" \
"com.samsung.android.smartcallprovider" \
"com.sec.android.app.setupwizardlegalprovider" \
"com.samsung.ecomm" \
"com.samsung.android.spay" \
"com.sec.android.app.shealth" \
"com.sec.android.app.setupwizard" \
"com.samsung.android.dynamiclock" \
"com.samsung.android.samsungpassautofill" \
"com.samsung.android.authfw" \
"com.samsung.android.ipsgeofence" \
"com.sec.android.app.billing" \
"com.samsung.android.da.daagent" \
"com.samsung.android.spayfw" \
"com.google.android.onetimeinitializer" \
"com.samsung.android.bixby.agent" \
"com.samsung.android.bixby.wakeup" \
"com.samsung.knox.securefolder" \
"com.samsung.android.oneconnect" \
"com.samsung.android.scloud" \
"com.samsung.android.beaconmanager" \
"com.sec.android.app.sbrowser" \
"com.samsung.android.app.reminder" \
"android.autoinstalls.config.samsung" \
"com.sec.android.app.SecSetupWizard" \
"com.samsung.android.arzone" \
"com.samsung.android.fmm" \
"com.google.android.apps.restore" \
"com.samsung.android.easysetup" \
"com.samsung.android.stickercenter" \
"com.samsung.android.sdm.config" \
"com.samsung.android.aremoji" \
"com.samsung.android.fast" \
"com.samsung.android.rubin.app"
)
for package in "${packages_to_uninstall[@]}"
do
echo "Uninstalling $package..."
adb shell pm uninstall -k --user 0 $package
done
for package in "${packages_to_disable[@]}"
do
echo "Disabling $package..."
adb shell pm disable-user --user 0 $package
done
@jzallas
Copy link
Author

jzallas commented Jul 20, 2024

definitions.json was just pulled from here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment