Skip to content

Instantly share code, notes, and snippets.

Avatar

Christopher Piekarski chris-piekarski

View GitHub Profile
@chris-piekarski
chris-piekarski / x11_ssh
Last active Aug 29, 2015
Headless Ubuntu X11 SSH Tunnel
View x11_ssh
On SSH server make sure the sshd config file contains "X11Forwarding yes" (/etc/ssh/sshd_config).
On the client add -X flag to ssh command ( ssh -X myusername@myhost.com ). Then simply run X11 programs.
@chris-piekarski
chris-piekarski / aosp_pid
Last active Aug 29, 2015
Android Process Pid
View aosp_pid
android.os.Process.myPid()
android.os.Process.killProcess(android.os.Process.myPid())
@chris-piekarski
chris-piekarski / adb_aosp_content
Last active Apr 12, 2021
ADB Content Command
View adb_aosp_content
adb shell content delete --uri content://settings/settings/pointer_speed
adb shell content query --uri content://settings/settings
adb shell content insert --uri content://settings/secure --bind name:s:my_number --bind value:i:24
See "package com.android.commands.content;" in /frameworks/base/cmds/content/
Usese "final class ContentProviderProxy implements IContentProvider" in ContentProviderProxy.java
@chris-piekarski
chris-piekarski / android_wifi_status
Last active Aug 29, 2015
Properly control Android service state based on Wifi status
View android_wifi_status
private void registerConnectivityChange() {
BroadcastReceiver connectionReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// When just using the ConnectivityManager you can get identical intents
// twice within one second. So we need to use the WifiManager & ConnectivityManager
// to determine true state
if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
NetworkInfo networkInfo = intent
@chris-piekarski
chris-piekarski / intent_package_name
Created Jan 22, 2014
Log package name of incoming Intent
View intent_package_name
import android.content.pm.PackageManager;
import android.os.Binder;
import android.content.Intent;
class {
@Override
public void onReceive(Context context, Intent intent) {
Log.v(TAG, context.getPackageManager().getNameForUid(Binder.getCallingUid()));
}
}
View android_timezone_listener
public static void registerTimezoneListener() {
IntentFilter timezoneFilter = new IntentFilter(Intent.ACTION_TIMEZONE_CHANGED);
BroadcastReceiver timezoneReceiver = new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent){
Log.d(TAG, "TIMEZONE CHANGED!");
}
};
Context.registerReceiver(timezoneReceiver, timezoneFilter);
@chris-piekarski
chris-piekarski / HelloWorldApp.java
Last active Jan 2, 2016
How does Java try/catch/finally work?
View HelloWorldApp.java
package com.cpiekarski.helloworld;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
/**
* javac -d . HelloWorldApp.java
* java -cp . com.cpiekarski.helloworld.HelloWorldApp
@chris-piekarski
chris-piekarski / android_cert_paths
Created Dec 18, 2013
Android TrustedCertificateStore.java Cert Paths
View android_cert_paths
String ANDROID_ROOT = System.getenv("ANDROID_ROOT");
String ANDROID_DATA = System.getenv("ANDROID_DATA");
CA_CERTS_DIR_SYSTEM = new File(ANDROID_ROOT + "/etc/security/cacerts");
CA_CERTS_DIR_ADDED = new File(ANDROID_DATA + "/misc/keychain/cacerts-added");
CA_CERTS_DIR_DELETED = new File(ANDROID_DATA + "/misc/keychain/cacerts-removed");
@chris-piekarski
chris-piekarski / android_js_webview_proguard
Created Dec 11, 2013
Android Webview JavaScript and Proguard
View android_js_webview_proguard
In the project proguard-project.txt file see:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
-keepclassmembers class com.me.MeWebViewHelper.MyJSInterface {
public *;
}
View list_android_sensors
import android.hardware.SensorManager;
private SensorManager mSensorManager;
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
List<Sensor> deviceSensors = mSensorManager.getSensorList(Sensor.TYPE_ALL);