Skip to content

Instantly share code, notes, and snippets.

View scottyab's full-sized avatar

Scott Alexander-Bown scottyab

View GitHub Profile
@scottyab
scottyab / SampleEncPrefs.kt
Created July 24, 2019 20:12
Simple example of using EncrypredSharedPreferences
package com.scottyab.whatsnewplayground.data
import android.content.Context
import android.content.SharedPreferences
import androidx.security.crypto.EncryptedSharedPreferences
import androidx.security.crypto.MasterKeys
import com.scottyab.whatsnewplayground.BuildConfig
internal class SampleEncPrefs(context: Context) {
@scottyab
scottyab / SignatureCheck.java
Last active January 30, 2024 15:22
Simple Android signature check. Please note: This was created in 2013, not actively maintained and may not be compatible with the latest Android versions. It's not particularly difficult for an attacker to decompile an .apk, find this tamper check, replace the APP_SIGNATURE with theirs and rebuild (or use method hooking to return true from `vali…
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.Signature;
public class TamperCheck {
//we store the hash of the signture for a little more protection
private static final String APP_SIGNATURE = "1038C0E34658923C4192E61B16846";
@scottyab
scottyab / meetup-graphql-query-variables.txt
Last active September 26, 2023 09:45
Query all the past events a meetup.com group has hosted. Meetup doesn’t great way of surfacing a meetup groups past events (paging through the calendar is PITA). This GraphQL query can be run from the MeetupAPI GraphQL playground https://www.meetup.com/api/playground/#graphQl-playground
{ "urlname": "YOUR URL PATH here, for https://www.meetup.com/swmobile the urlname is swmobile" }
@scottyab
scottyab / AssertExtensions.kt
Created March 20, 2023 10:31
Assert `isInstanceOf` extensions to improve readablity of JUnit test assertions. I've found this most useful when asserting sealed class result objects as you can asset it's the correct type and then via smart casting continue to assert any specifics of the result, in the sample below I assert the type and then taskId.
import org.assertj.core.api.AbstractObjectAssert
@Suppress("UNCHECKED_CAST")
inline fun <reified R> AbstractObjectAssert<*, *>.isNotInstanceOf(): AbstractObjectAssert<*, *>? =
isNotInstanceOf(R::class.java)
@Suppress("UNCHECKED_CAST")
inline fun <reified R> AbstractObjectAssert<*, *>.isInstanceOf(): AbstractObjectAssert<*, *>? =
isInstanceOf(R::class.java)
@scottyab
scottyab / KoltinUnitTestTemplate.kt
Created February 9, 2023 11:46
Jetbrains IDE code template for JUnit tests written in Kotlin.
package ${PACKAGE_NAME}
import com.nhaarman.mockitokotlin2.verify
import com.nhaarman.mockitokotlin2.whenever
import org.assertj.core.api.Assertions.assertThat
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.junit.MockitoJUnitRunner
@scottyab
scottyab / firebase-hosting-deploy.yml
Last active January 4, 2023 09:51
Github action used on Scottyab.com to Build Jekyll and Deploy to Firebase Hosting when commits pushed to main. `GITHUB_TOKEN`, `FIREBASE_PROJECT_ID`, `FIREBASE_SERVICE_ACCOUNT` will vary for your setup and need to be configured via Githuib repo settings..
name: Build and Deploy to Firebase
'on':
push:
branches:
- main
jobs:
build_and_deploy:
name: Build and deploy Jekyll site
runs-on: ubuntu-latest
@scottyab
scottyab / SaferWebViewClient.java
Created May 14, 2014 15:36
Make Webview safer - some of the code based on recommendations in article https://labs.mwrinfosecurity.com/blog/2012/04/23/adventures-with-android-webviews/
/**
* Implements whitelisting on host name
*/
public class SaferWebViewClient extends WebViewClient {
private String[] hostsWhitelist;
public SaferWebViewClient(String hostsWhitelsit){
super();
this.hostsWhitelist = hostsWhitelist;
@scottyab
scottyab / MyAppFirebaseMessagingService.kt
Last active August 17, 2020 13:32
Sample of how an app "MyApp" would intergrate and enable Beacon SDK push notifications
class MyAppFirebaseMessagingService : FirebaseMessagingService() {
override fun onMessageReceived(remoteMessage: RemoteMessage) {
if(remoteMessage.data.isNotEmpty()) {
processNewMessage(remoteMessage.data)
}
}
private fun processNewMessage(remoteMessageData: Map<String, String>) {
if (BeaconPushNotificationsProcessor.isBeaconNotification(remoteMessageData)) {
@scottyab
scottyab / Installer
Created September 17, 2014 14:55
Tamper checks
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
public class InstallerCheck{
private static final String PLAY_STORE_APP_ID = "com.google.android";
public static boolean verifyInstaller(final Context context) {
@scottyab
scottyab / Coloring.java
Created October 29, 2018 15:22 — forked from milosmns/Coloring.java
Android: Coloring (Helper Class)
package me.angrybyte.coloringdemo;
import static android.graphics.PorterDuff.Mode.SRC_ATOP;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Bitmap;